-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(oci): better integration OCI storage with AWS ECR
resolves #2938
- Loading branch information
Showing
18 changed files
with
474 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
storage: | ||
type: oci | ||
oci: | ||
repository: some.target/repository/abundle:latest | ||
bundles_directory: /tmp/bundles | ||
authentication: | ||
type: aws-ecr | ||
poll_interval: 5m |
8 changes: 8 additions & 0 deletions
8
internal/config/testdata/storage/oci_provided_invalid_auth.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
storage: | ||
type: oci | ||
oci: | ||
repository: some.target/repository/abundle:latest | ||
bundles_directory: /tmp/bundles | ||
poll_interval: 5m | ||
authentication: | ||
type: invalid |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
storage: | ||
type: oci | ||
oci: | ||
repository: some.target/repository/abundle:latest | ||
bundles_directory: /tmp/bundles | ||
poll_interval: 5m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package ecr | ||
|
||
import ( | ||
"context" | ||
"encoding/base64" | ||
"errors" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/service/ecr" | ||
"oras.land/oras-go/v2/registry/remote/auth" | ||
) | ||
|
||
var ErrNoAWSECRAuthorizationData = errors.New("no ecr authorization data provided") | ||
|
||
type Client interface { | ||
GetAuthorizationToken(ctx context.Context, params *ecr.GetAuthorizationTokenInput, optFns ...func(*ecr.Options)) (*ecr.GetAuthorizationTokenOutput, error) | ||
} | ||
|
||
type ECR struct { | ||
client Client | ||
} | ||
|
||
func (r *ECR) CredentialFunc(registry string) auth.CredentialFunc { | ||
return r.Credential | ||
} | ||
|
||
func (r *ECR) Credential(ctx context.Context, hostport string) (auth.Credential, error) { | ||
cfg, err := config.LoadDefaultConfig(context.Background()) | ||
if err != nil { | ||
return auth.EmptyCredential, err | ||
} | ||
r.client = ecr.NewFromConfig(cfg) | ||
return r.fetchCredential(ctx) | ||
} | ||
|
||
func (r *ECR) fetchCredential(ctx context.Context) (auth.Credential, error) { | ||
response, err := r.client.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{}) | ||
if err != nil { | ||
return auth.EmptyCredential, err | ||
} | ||
if len(response.AuthorizationData) == 0 { | ||
return auth.EmptyCredential, ErrNoAWSECRAuthorizationData | ||
} | ||
token := response.AuthorizationData[0].AuthorizationToken | ||
|
||
if token == nil { | ||
return auth.EmptyCredential, auth.ErrBasicCredentialNotFound | ||
} | ||
|
||
output, err := base64.StdEncoding.DecodeString(*token) | ||
if err != nil { | ||
return auth.EmptyCredential, err | ||
} | ||
|
||
userpass := strings.SplitN(string(output), ":", 2) | ||
if len(userpass) != 2 { | ||
return auth.EmptyCredential, auth.ErrBasicCredentialNotFound | ||
} | ||
|
||
return auth.Credential{ | ||
Username: userpass[0], | ||
Password: userpass[1], | ||
}, nil | ||
} |
Oops, something went wrong.