logo
Alauda DevOps Pipelines Docs
logo
Alauda DevOps Pipelines Docs
Navigation

Overview

Introduction
Architecture
Feature Overview
Lifecycle Policy
Quick Start
Release Notes

Concepts

TektonConfig
TektonPipeline
Install
Upgrade

Configure

Adjusting Optional Configuration Items of Subcomponents
Configuring Resource Quotas for Pipeline Components
Pod Template Configuration Guide
Regular Cleanup of TaskRun and PipelineRun Resources

How To

Deploying tekton-pipelines in a global cluster through TektonConfig

Pipelines

Introduction
Architecture

Concepts

Tasks
TaskRuns
Pipelines
PipelineRuns
StepActions
Resolvers
Workspaces
Pod Templates
Quick Start
permissions

how_to

Adjust Dockerfile for Building Task-Compatible Custom Images

trouble_shooting

Failed to create pod due to config error when using custom images in Tekton

Triggers

Introduction
Architecture

Core Concepts

Core Concepts
EventListener
Trigger
Interceptor
TriggerBinding
TriggerTemplate
Quick Start

How To

Setup EventListener
Use GitLab Event Triggers
Create TriggerTemplate

Troubleshooting

The Pipeline is not automatically triggered
Permission Description

Hub

Introduction
Architecture

Core Concepts

Concepts
Understanding Tekton Hub
Permission Description

Configure

Tekton Hub Configuration
Adding Custom Catalogs

Tutorials

Creating a Custom Catalog
Writing Tasks for Tekton Hub
Writing Pipelines for Tekton Hub

Results

Introduction
Architecture

Concepts

Core Concepts
Tekton Results
Quick Start
permissions

Configure

Database Configuration

Supply Chain Security

Introduction
Architecture

Concepts

Core Concepts
Understanding Tekton Chains
Quick Start

API Reference

Introduction

Kubernetes APIs

Pipelines

Pipeline [tekton.dev/v1]
Task [tekton.dev/v1]
PipelineRun [tekton.dev/v1]
TaskRun [tekton.dev/v1]
ClusterTask [tekton.dev/v1]
Run [tekton.dev/v1]
CustomRun [tekton.dev/v1]
StepAction [tekton.dev/v1]
VerificationPolicy [tekton.dev/v1alpha1]
ResolutionRequest [resolution.tekton.dev/v1beta1]

Triggers

Trigger [triggers.tekton.dev/v1beta1]
TriggerTemplate [triggers.tekton.dev/v1beta1]
EventListener [triggers.tekton.dev/v1beta1]
TriggerBinding [triggers.tekton.dev/v1beta1]
Interceptor [triggers.tekton.dev/v1alpha1]
ClusterTriggerBinding [triggers.tekton.dev/v1beta1]
ClusterInterceptor [triggers.tekton.dev/v1alpha1]

Operator

TektonConfig [operator.tekton.dev/v1alpha1]
TektonInstallerSet [operator.tekton.dev/v1alpha1]
TektonPipeline [operator.tekton.dev/v1alpha1]
TektonTrigger [operator.tekton.dev/v1alpha1]
TektonChain [operator.tekton.dev/v1alpha1]
TektonHub [operator.tekton.dev/v1alpha1]
TektonResult [operator.tekton.dev/v1alpha1]
TektonInstallerSet [operator.tekton.dev/v1alpha1]
OpenShift Pipelines as Code [operator.tekton.dev/v1alpha1]

Advanced APIs

Results

Introduction to API Usage
Results List
Results Details
Result records List
Result logs List
📝 Edit this page on GitHub
Previous Pagepermissions
Next PageFailed to create pod due to config error when using custom images in Tekton

#Adjust Dockerfile for Building Task-Compatible Custom Images

#TOC

#Feature Overview

In Tekton, to enhance security, Tasks may be configured with runAsNonRoot: true, which requires containers to run as non-root users. Therefore, special attention must be given to the configuration of the Dockerfile when building custom images to ensure that the images can operate correctly in such Tasks.

This document describes how to adjust the Dockerfile to build custom images that are compatible with Tasks, focusing on user permission configurations.

#Use Cases

The following scenarios require referring to the guidance in this document:

  • Building a custom image for use in Tasks
  • Encountering permission-related errors when running existing images in Tasks
  • Ensuring the image meets the security requirements of Tasks

#Prerequisites

Before using this feature, ensure:

  • You have a Docker image building environment
    • You can use the platform's native build pipeline
    • If you need to use community/open-source tools, ensure you have internet access or have prepared offline packages
  • You have a basic understanding of Dockerfile writing
    • You can refer to the Dockerfile Official Documentation
    • Understand Dockerfile Best Practices
  • A Dockerfile file and related configuration

#Steps

#1. Confirm the Base Image

First, confirm the release version of the base image, as the command for creating a user may differ between versions:

# Check the release version of the base image
$ docker run -it --rm ${registry} cat /etc/os-release

# Possible outputs
NAME="Alpine Linux"
# or
NAME="Debian GNU/Linux"
# or
NAME="Ubuntu"
# or
NAME="CentOS Linux"

#2. Add a Non-Root User

Add a non-root user in the Dockerfile (it is recommended to use UID 65532):

# Based on the base image, choose the corresponding command

# Alpine
RUN adduser -u 65532 -h /home/nonroot -D nonroot

# Debian
RUN adduser --home /home/nonroot --uid 65532 nonroot --disabled-password --gecos ""

# Ubuntu
RUN apt-get update && apt-get install -y adduser \
    && adduser --home /home/nonroot --uid 65532 nonroot --disabled-password --gecos ""

# CentOS
RUN groupadd -g 65532 nonroot && useradd -u 65532 -U -d /home/nonroot -m nonroot

#3. Set Necessary Permissions for the User (Optional)

If the user needs to access certain directories or files, necessary permissions should be added for that user.

# Set the owner of the directory or file to nonroot
RUN chown -R nonroot:nonroot /path/to/directory

# Alternatively, set the permissions of the directory or file to allow everyone to read and write or to other minimal permissions
RUN chmod -R a+rwx /path/to/directory

#4. Set the Default User

Set the default user in the Dockerfile (using UID instead of the username):

Since Pods configured with runAsNonRoot will check if the user ID is a non-root user rather than checking the username.

# Set the default user to nonroot (using UID)
USER 65532

#5. Validate the Image

After building, validate whether the image can run correctly:

# Verify user configuration
$ docker run -it --rm ${registry} id

# Expected output
uid=65532(nonroot) gid=65532(nonroot) groups=65532(nonroot)

# Verify application permissions
$ docker run -it --rm ${registry} ls -la /home/nonroot

#Operation Results

With this configuration:

  1. User Configuration

    • UID 65532 is consistently used, allowing files generated in multiple Tasks to have consistent access permissions
    • Ensure the user has appropriate working directory permissions
    • Avoid using the root user or UID 0
  2. Application Configuration

    • Ensure applications can run normally as non-root users
    • Pre-configure necessary directory permissions in the Dockerfile
    • Use the VOLUME instruction to define directories that need to be persisted
  3. Security Recommendations

    • Regularly update the base image to fix security vulnerabilities
    • Use multi-stage builds to reduce image size
    • Follow the principle of least privilege when configuring user permissions

#Troubleshooting

If permission issues occur when running the image in Tasks, you can:

  1. Check the error messages in Pod events
  2. Verify if the user configuration in the image is correct
  3. Ensure that the required permissions for the application are configured

#Learn More

  • Dockerfile Official Documentation
  • Dockerfile Best Practices