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 PageAdjust Dockerfile for Building Task-Compatible Custom Images
Next PageTriggers

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

#TOC

#Problem Description

In the Tekton pipeline, using images provided by the product works correctly, but when using user-defined images, you may encounter TaskRun execution failures.

#Error Manifestation

  1. TaskRun execution fails with a status of False, and the reason is CreateContainerConfigError:

    $ kubectl get taskruns -n ${namespace} ${taskrun_name}
    NAME                     SUCCEEDED   REASON                       STARTTIME   COMPLETIONTIME
    hello-c7pnj-run-script   False       CreateContainerConfigError   9m43s
  2. The TaskRun event displays an error message:

    Failed: Failed to create pod due to config error
  3. Relevant pod events show an error message:

    Failed: Error: container's runAsUser breaks non-root policy

#Root Cause Analysis

Such issues are typically caused by the following two reasons:

  1. The image itself has issues.
  2. The image is incompatible with the Task configuration.

#Troubleshooting

If this issue only appears when using custom images, it is recommended to follow these steps for troubleshooting:

  1. Verify if the image itself has issues:

    $ docker run -it --rm ${registry} ${cmd}
  2. Check the compatibility of the Task configuration with the image:

    • Check if the Task is configured with runAsNonRoot: true.
    • Check whether the default user of the image is root or a non-numeric user ID.

Example Task configuration:

apiVersion: tekton.dev/v1
kind: Task
metadata:
  name: foo
spec:
  steps:
    - name: bar
      securityContext:
        runAsNonRoot: true

Example Dockerfile configuration:

USER root

#Solution

#Option 1: Adjust Image Build Configuration to Set the Default User to a Non-root User

#Prerequisites

  • Environment and permissions to rebuild the image.

#Steps

Refer to Adjust Dockerfile for Task-Compatible Custom Images to modify the Dockerfile configuration.

#Option 2: Modify TaskRun or PipelineRun Execution Configuration

#Prerequisites

  • Permissions to modify TaskRun or PipelineRun.

#Steps

  1. Add configuration when executing TaskRun separately:

    apiVersion: tekton.dev/v1
    kind: TaskRun
    metadata:
      name: foo
    spec:
      taskRef:
        name: foo
      podTemplate:
        securityContext:
          runAsUser: 65532
  2. Add configuration when executing PipelineRun:

    # Method 1: Add configuration for all Tasks
    apiVersion: tekton.dev/v1
    kind: PipelineRun
    spec:
      taskRunTemplate:
        podTemplate:
          securityContext:
            runAsUser: 65532
    
    # Method 2: Add configuration for specific Tasks
    apiVersion: tekton.dev/v1
    kind: PipelineRun
    spec:
      taskRunSpecs:
        - pipelineTaskName: example-git-clone
          podTemplate:
            securityContext:
              runAsUser: 65532
              fsGroup: 65532

#Option 3: Modify Global Tekton Configuration

#Prerequisites

  • Cluster operation permissions.
  • Permissions to modify the TektonConfig resource.
  • Note: This configuration will affect all Tasks.

#Steps

  1. Modify the TektonConfig resource: Increase the following spec.pipeline.default-pod-template configuration:

    apiVersion: config.tekton.dev/v1beta1
    kind: TektonConfig
    metadata:
      name: config
    spec:
      pipeline:
        default-pod-template: |
          securityContext:
            runAsUser: 65532
  2. Verify whether the configuration takes effect:

    $ kubectl get configmap -n tekton-pipelines config-defaults -o yaml | grep 'default-pod-template: |' -A2
    
    # Expected output
    default-pod-template: |
      securityContext:
        runAsUser: 65532

#Option 4: Modify Task Definition

#Prerequisites

  • Permissions to modify the Task.
  • Note: This configuration will affect all TaskRuns or PipelineRuns that use this Task.

#Steps

  1. Method 1: Remove runAsNonRoot configuration:

    apiVersion: tekton.dev/v1
    kind: Task
    metadata:
      name: foo
    spec:
      steps:
        - name: bar
          securityContext:
            # runAsNonRoot: true
  2. Method 2: Add runAsUser configuration:

    apiVersion: tekton.dev/v1
    kind: Task
    metadata:
      name: foo
    spec:
      steps:
        - name: bar
          securityContext:
            runAsNonRoot: true
            runAsUser: 65532

#Prevent Errors

  1. Image Building

    • Prioritize using non-root users for building images.
    • Use UID 65532 as the non-root user consistently.
    • Ensure that the application can run normally with a non-root user.
  2. Task Configuration

    • Decide whether to enable runAsNonRoot based on security requirements.
    • If required, configure runAsUser accordingly.
  3. Permission Management

    • Follow the principle of least privilege.
    • Plan directory permissions in advance.
    • Regularly review permission configurations.

#Related Content

  • Adjust Dockerfile for Task-Compatible Custom Images
  • Official Dockerfile Documentation
  • Dockerfile Best Practices