@@ -852,11 +852,15 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
852852 Name : "workspace" ,
853853 MountPath : "/workspace" ,
854854 },
855+ {
856+ Name : consts .DockerConfigVolumeName ,
857+ MountPath : consts .DockerConfigVolumeMountPath ,
858+ },
855859 }
856860
857861 if dockerConfigJSONSecretName != "" {
858862 volumes = append (volumes , corev1.Volume {
859- Name : dockerConfigJSONSecretName ,
863+ Name : consts . DockerConfigVolumeName ,
860864 VolumeSource : corev1.VolumeSource {
861865 Secret : & corev1.SecretVolumeSource {
862866 SecretName : dockerConfigJSONSecretName ,
@@ -869,9 +873,12 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
869873 },
870874 },
871875 })
872- volumeMounts = append (volumeMounts , corev1.VolumeMount {
873- Name : dockerConfigJSONSecretName ,
874- MountPath : "/kaniko/.docker/" ,
876+ } else {
877+ volumes = append (volumes , corev1.Volume {
878+ Name : consts .DockerConfigVolumeName ,
879+ VolumeSource : corev1.VolumeSource {
880+ EmptyDir : & corev1.EmptyDirVolumeSource {},
881+ },
875882 })
876883 }
877884
@@ -921,8 +928,6 @@ func (r *DynamoComponentReconciler) generateImageBuilderPodTemplateSpec(ctx cont
921928
922929 buildEngine := getDynamoComponentImageBuildEngine ()
923930
924- privileged := buildEngine != DynamoComponentImageBuildEngineBuildkitRootless
925-
926931 dynamoComponentDownloadCommandTemplate , err := template .New ("downloadCommand" ).Parse (`
927932set -e
928933
@@ -943,10 +948,6 @@ echo "Extracting dynamoComponent tar file..."
943948tar -xvf /tmp/downloaded.tar
944949echo "Removing dynamoComponent tar file..."
945950rm /tmp/downloaded.tar
946- {{if not .Privileged}}
947- echo "Changing directory permission..."
948- chown -R 1000:1000 /workspace
949- {{end}}
950951echo "Done"
951952 ` )
952953
@@ -961,7 +962,6 @@ echo "Done"
961962 "DynamoComponentDownloadURL" : dynamoComponentDownloadURL ,
962963 "DynamoComponentRepositoryName" : dynamoComponentRepositoryName ,
963964 "DynamoComponentVersion" : dynamoComponentVersion ,
964- "Privileged" : privileged ,
965965 })
966966 if err != nil {
967967 err = errors .Wrap (err , "failed to execute download command template" )
@@ -1004,6 +1004,38 @@ echo "Done"
10041004 },
10051005 }
10061006
1007+ if dockerConfigJSONSecretName == "" {
1008+ // if no explicit docker config is provided, we need to provide the docker config to the image builder
1009+ dockerRegistry := strings .Split (imageName , "/" )[0 ]
1010+ if isGoogleRegistry (dockerRegistry ) {
1011+ // for GCP, we use the google cloud sdk to get the docker config.
1012+ initContainers = append (initContainers , corev1.Container {
1013+ Name : "gcp-init-docker-config" ,
1014+ Image : "google/cloud-sdk:slim" ,
1015+ Command : []string {
1016+ "/bin/bash" ,
1017+ "-c" ,
1018+ fmt .Sprintf (`
1019+ TOKEN=$(gcloud auth print-access-token)
1020+ cat > %s/config.json <<EOL
1021+ {
1022+ "auths": {
1023+ "%s": {
1024+ "auth": "$(echo -n "oauth2accesstoken:${TOKEN}" | base64 -w 0)"
1025+ }
1026+ }
1027+ }
1028+ EOL
1029+ echo 'Docker config.json created successfully'
1030+ ` , consts .DockerConfigVolumeMountPath , dockerRegistry ),
1031+ },
1032+ Resources : downloaderContainerResources ,
1033+ EnvFrom : downloaderContainerEnvFrom ,
1034+ VolumeMounts : volumeMounts ,
1035+ })
1036+ }
1037+ }
1038+
10071039 containers := make ([]corev1.Container , 0 )
10081040
10091041 var globalExtraPodMetadata * dynamoCommon.ExtraPodMetadata
@@ -1111,13 +1143,10 @@ echo "Done"
11111143 Name : "IFS" ,
11121144 Value : "''" ,
11131145 },
1114- }
1115-
1116- if dockerConfigJSONSecretName != "" {
1117- builderContainerEnvs = append (builderContainerEnvs , corev1.EnvVar {
1146+ {
11181147 Name : "DOCKER_CONFIG" ,
1119- Value : "/kaniko/.docker/" ,
1120- })
1148+ Value : consts . DockerConfigVolumeMountPath ,
1149+ },
11211150 }
11221151
11231152 kanikoCacheRepo := os .Getenv ("KANIKO_CACHE_REPO" )
@@ -1174,9 +1203,6 @@ echo "Done"
11741203 if isBuildkit {
11751204 output := fmt .Sprintf ("type=image,name=%s,push=true,registry.insecure=%v" , imageName , dockerRegistryInsecure )
11761205 buildkitdFlags := []string {}
1177- if ! privileged {
1178- buildkitdFlags = append (buildkitdFlags , "--oci-worker-no-process-sandbox" )
1179- }
11801206 if isEstargzEnabled () {
11811207 buildkitdFlags = append (buildkitdFlags , "--oci-worker-snapshotter=stargz" )
11821208 output += ",oci-mediatypes=true,compression=estargz,force-compression=true"
@@ -1215,23 +1241,6 @@ echo "Done"
12151241 }
12161242 }
12171243
1218- var builderContainerSecurityContext * corev1.SecurityContext
1219-
1220- if buildEngine == DynamoComponentImageBuildEngineBuildkit {
1221- builderContainerSecurityContext = & corev1.SecurityContext {
1222- Privileged : ptr .To (true ),
1223- }
1224- } else if buildEngine == DynamoComponentImageBuildEngineBuildkitRootless {
1225- kubeAnnotations ["container.apparmor.security.beta.kubernetes.io/builder" ] = "unconfined"
1226- builderContainerSecurityContext = & corev1.SecurityContext {
1227- SeccompProfile : & corev1.SeccompProfile {
1228- Type : corev1 .SeccompProfileTypeUnconfined ,
1229- },
1230- RunAsUser : ptr .To (int64 (1000 )),
1231- RunAsGroup : ptr .To (int64 (1000 )),
1232- }
1233- }
1234-
12351244 // add build args to pass via --build-arg
12361245 for _ , buildArg := range buildArgs {
12371246 quotedBuildArg := unix .SingleQuote .Quote (buildArg )
@@ -1261,7 +1270,6 @@ echo "Done"
12611270 EnvFrom : builderContainerEnvFrom ,
12621271 TTY : true ,
12631272 Stdin : true ,
1264- SecurityContext : builderContainerSecurityContext ,
12651273 }
12661274
12671275 if globalDefaultImageBuilderContainerResources != nil {
@@ -1284,6 +1292,11 @@ echo "Done"
12841292 Volumes : volumes ,
12851293 InitContainers : initContainers ,
12861294 Containers : containers ,
1295+ SecurityContext : & corev1.PodSecurityContext {
1296+ RunAsUser : ptr .To (int64 (1000 )),
1297+ RunAsGroup : ptr .To (int64 (1000 )),
1298+ FSGroup : ptr .To (int64 (1000 )),
1299+ },
12871300 },
12881301 }
12891302
0 commit comments