Compare commits

..

4 Commits

Author SHA1 Message Date
Ompragash Viswanathan 85f1c74d13 ECR auth for push-only operation + code refactoring 2025-04-16 13:29:50 +05:30
OP (oppenheimer) af2add0aa5 Update pipeline drone-kaniko-harness (#143) 2025-04-09 19:24:48 +05:30
OP (oppenheimer) 58bd727c07 feat: [CI-16588]: Add support to PLUGIN_TAR_PATH, PLUGIN_SOURCE_TAR_PATH and PLUGIN_PUSH_ONLY to kaniko-ecr (#141)
* Add support for tar-path, source-tar-path and push-only operations

* Updated cmd/kaniko-ecr/main.go

* Updated cmd/kaniko-ecr/main.go

* Update cmd/kaniko-ecr/main.go
2025-03-24 21:31:18 +05:30
ci-reporunner a73b8ee28d Update pipeline drone-kaniko-harness (#142)
Co-authored-by: ompragash.viswanathan@harness.io <ompragash.viswanathan@harness.io>
2025-03-20 19:10:13 +05:30
2 changed files with 80 additions and 77 deletions
+3 -28
View File
@@ -12,32 +12,6 @@ pipeline:
build: <+input>
sparseCheckout: []
stages:
- stage:
name: Manager Approval
identifier: Manager_Approval
description: ""
type: Approval
spec:
execution:
steps:
- step:
name: CI Manager Approval
identifier: CI_Manager_Approval
type: HarnessApproval
timeout: 1d
spec:
approvalMessage: |-
Please review the following information
and approve the pipeline progression
includePipelineExecutionHistory: true
approvers:
minimumCount: 1
disallowPipelineExecutor: false
userGroups:
- CI_Manager
isAutoRejectEnabled: false
approverInputs: []
tags: {}
- parallel:
- stage:
name: linux-amd64
@@ -655,13 +629,13 @@ pipeline:
nodeName: manifest_<+matrix.repo>
- step:
type: Plugin
name: Manifest_kaniko
name: Manifest_kaniko191
identifier: Manifest_kaniko
spec:
connectorRef: Plugins_Docker_Hub_Connector
image: plugins/manifest
settings:
auto_tag: "true"
auto_tag: "false"
spec: docker/<+matrix.repo>/manifest-kaniko1.9.1.tmpl
username: drone
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
@@ -679,3 +653,4 @@ pipeline:
nodeName: manifest_<+matrix.repo>
when:
pipelineStatus: Success
allowStageExecutions: true
+77 -49
View File
@@ -879,6 +879,72 @@ func getOidcCreds(oidcToken, assumeRole string) (string, string, string, error)
return *result.Credentials.AccessKeyId, *result.Credentials.SecretAccessKey, *result.Credentials.SessionToken, nil
}
func createECRSession(region, accessKey, secretKey, sessionToken string) *ecrv1.ECR {
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(region),
Credentials: credentials.NewStaticCredentials(
accessKey,
secretKey,
sessionToken,
),
}))
return ecrv1.New(sess)
}
func getECRCredentials(region, registry, assumeRole, externalId, accessKey, secretKey, oidcToken string) (string, string, error) {
if assumeRole != "" && oidcToken != "" {
// For OIDC auth with assume role
awsAccessKey, awsSecretKey, awsSessionToken, err := getOidcCreds(oidcToken, assumeRole)
if err != nil {
return "", "", fmt.Errorf("failed to get OIDC credentials: %w", err)
}
// Create ECR session and get auth info
svc := createECRSession(region, awsAccessKey, awsSecretKey, awsSessionToken)
username, password, _, err := getAuthInfo(svc)
if err != nil {
return "", "", fmt.Errorf("failed to get ECR credentials: %w", err)
}
return username, password, nil
} else if assumeRole != "" {
// For assume role auth
username, password, _, err := getAssumeRoleCreds(region, assumeRole, externalId, "")
if err != nil {
return "", "", fmt.Errorf("failed to get ECR credentials: %w", err)
}
return username, password, nil
} else if accessKey != "" && secretKey != "" {
// For direct credentials
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(region),
Credentials: credentials.NewStaticCredentials(
accessKey,
secretKey,
"",
),
}))
svc := ecrv1.New(sess)
username, password, _, err := getAuthInfo(svc)
if err != nil {
return "", "", fmt.Errorf("failed to get ECR credentials: %w", err)
}
return username, password, nil
} else {
// For IAM role auth (default credentials)
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(region),
}))
svc := ecrv1.New(sess)
username, password, _, err := getAuthInfo(svc)
if err != nil {
return "", "", fmt.Errorf("failed to get ECR credentials: %w", err)
}
return username, password, nil
}
}
func handlePushOnly(c *cli.Context) error {
sourceTarPath := c.String("source-tar-path")
if sourceTarPath == "" {
@@ -901,56 +967,18 @@ func handlePushOnly(c *cli.Context) error {
return fmt.Errorf("failed to load image from tarball: %v", err)
}
// Get ECR credentials using existing auth methods
var username, password string
var svc *ecrv1.ECR
if oidcToken := c.String("oidc-token-id"); oidcToken != "" && c.String("assume-role") != "" {
accessKey, secretKey, sessionToken, err := getOidcCreds(oidcToken, c.String("assume-role"))
if err != nil {
return fmt.Errorf("failed to get OIDC credentials: %v", err)
}
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(c.String("region")),
Credentials: credentials.NewStaticCredentials(
accessKey,
secretKey,
sessionToken,
),
}))
svc = ecrv1.New(sess)
} else if assumeRole := c.String("assume-role"); assumeRole != "" {
accessKey, secretKey, sessionToken, err := getAssumeRoleCreds(c.String("region"), assumeRole, c.String("external-id"), "")
if err != nil {
return fmt.Errorf("failed to get assume role credentials: %v", err)
}
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(c.String("region")),
Credentials: credentials.NewStaticCredentials(
accessKey,
secretKey,
sessionToken,
),
}))
svc = ecrv1.New(sess)
} else {
// Use direct credentials or IAM role
sess := session.Must(session.NewSession(&awsv1.Config{
Region: awsv1.String(c.String("region")),
Credentials: credentials.NewStaticCredentials(
c.String("access-key"),
c.String("secret-key"),
"",
),
}))
svc = ecrv1.New(sess)
}
// Get ECR auth token using the configured session
username, password, _, err = getAuthInfo(svc)
// Get ECR credentials using the common function
username, password, err := getECRCredentials(
c.String("region"),
registry,
c.String("assume-role"),
c.String("external-id"),
c.String("access-key"),
c.String("secret-key"),
c.String("oidc-token-id"),
)
if err != nil {
return fmt.Errorf("failed to get ECR credentials: %v", err)
return err
}
// Setup crane auth