This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/terraform-provider-iceberg.git
The following commit(s) were added to refs/heads/main by this push:
new dc03a31 feat(provider): add auth.sigv4.profile (#168)
dc03a31 is described below
commit dc03a3168ce14cb6fcbee4b7648901b351a9b3d7
Author: Al Johri <[email protected]>
AuthorDate: Wed Nov 18 15:43:29 2026 -0500
feat(provider): add auth.sigv4.profile (#168)
Select a named profile from the shared AWS config for SigV4 signing.
Without it, the profile comes only from AWS_PROFILE, so a configuration
that uses one profile for the AWS provider cannot reuse it here.
---
docs/index.md | 1 +
internal/provider/provider.go | 14 ++++++++++++++
internal/provider/provider_sigv4_test.go | 32 ++++++++++++++++++++++++++++++++
3 files changed, 47 insertions(+)
diff --git a/docs/index.md b/docs/index.md
index 1c77ba9..4455a70 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -275,6 +275,7 @@ Optional:
Optional:
- `access_key_id` (String, Sensitive) Access key ID. When omitted, the
standard AWS credential chain (environment, shared config, instance role) is
used.
+- `profile` (String) Named profile from the shared AWS config and credentials
files. When omitted, the standard AWS credential chain selects the profile
(`AWS_PROFILE`, then `default`). Cannot be set together with `access_key_id`.
- `region` (String) Signing region. When omitted, the region from the AWS
environment (`AWS_REGION`, shared config) is used.
- `secret_access_key` (String, Sensitive) Secret access key. Must be set
together with `access_key_id`.
- `session_token` (String, Sensitive) Session token for temporary (STS)
credentials. Requires `access_key_id` and `secret_access_key`.
diff --git a/internal/provider/provider.go b/internal/provider/provider.go
index 1d0222e..63a4086 100644
--- a/internal/provider/provider.go
+++ b/internal/provider/provider.go
@@ -78,6 +78,7 @@ type oauth2Config struct {
type sigv4Config struct {
region string
signingName string
+ profile string
accessKeyID string
secretAccessKey string
sessionToken string
@@ -101,6 +102,7 @@ type icebergAuthModel struct {
type icebergSigV4Model struct {
Region types.String `tfsdk:"region"`
SigningName types.String `tfsdk:"signing_name"`
+ Profile types.String `tfsdk:"profile"`
AccessKeyID types.String `tfsdk:"access_key_id"`
SecretAccessKey types.String `tfsdk:"secret_access_key"`
SessionToken types.String `tfsdk:"session_token"`
@@ -163,6 +165,14 @@ func (p *icebergProvider) Schema(_ context.Context, _
provider.SchemaRequest, re
Description:
"Signing service name (the credential-scope service). Defaults to
`execute-api`. Use `glue` for AWS Glue.",
Optional:
true,
},
+ "profile":
schema.StringAttribute{
+ Description:
"Named profile from the shared AWS config and credentials files. When omitted,
the standard AWS credential chain selects the profile (`AWS_PROFILE`, then
`default`). Cannot be set together with `access_key_id`.",
+ Optional:
true,
+ Validators:
[]validator.String{
+
stringvalidator.LengthAtLeast(1),
+
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("access_key_id")),
+ },
+ },
"access_key_id":
schema.StringAttribute{
Description:
"Access key ID. When omitted, the standard AWS credential chain (environment,
shared config, instance role) is used.",
Optional:
true,
@@ -329,6 +339,7 @@ func (p *icebergProvider) Configure(ctx context.Context,
req provider.ConfigureR
p.sigv4 = &sigv4Config{
region: m.Region.ValueString(),
signingName:
m.SigningName.ValueString(),
+ profile:
m.Profile.ValueString(),
accessKeyID:
m.AccessKeyID.ValueString(),
secretAccessKey:
m.SecretAccessKey.ValueString(),
sessionToken:
m.SessionToken.ValueString(),
@@ -495,6 +506,9 @@ func (s *sigv4Config) awsConfig(ctx context.Context)
(aws.Config, error) {
// Only the region comes from the AWS environment, not its
credential chain.
load = append(load, config.WithCredentialsProvider(creds))
}
+ if s.profile != "" {
+ load = append(load, config.WithSharedConfigProfile(s.profile))
+ }
if s.region != "" {
load = append(load, config.WithRegion(s.region))
}
diff --git a/internal/provider/provider_sigv4_test.go
b/internal/provider/provider_sigv4_test.go
index 1ffb3c2..09e5103 100644
--- a/internal/provider/provider_sigv4_test.go
+++ b/internal/provider/provider_sigv4_test.go
@@ -325,3 +325,35 @@ func TestNewCatalogSharesConnectionsUnderSigV4(t
*testing.T) {
assert.Equal(t, int32(1), conns.Load(), "catalogs reuse one connection
pool instead of leaving one open each")
}
+
+func TestNewCatalogSignsWithConfiguredProfile(t *testing.T) {
+ isolateAWSEnv(t)
+ t.Setenv("AWS_ACCESS_KEY_ID", "")
+ t.Setenv("AWS_SECRET_ACCESS_KEY", "")
+ configFile := filepath.Join(t.TempDir(), "config")
+ require.NoError(t, os.WriteFile(configFile, []byte(`[profile ambient]
+aws_access_key_id = AMBIENTPROFILEKEY
+aws_secret_access_key = AMBIENTPROFILESECRET
+
+[profile named]
+aws_access_key_id = NAMEDKEY
+aws_secret_access_key = NAMEDSECRET
+region = eu-central-1
+`), 0o600))
+ t.Setenv("AWS_CONFIG_FILE", configFile)
+ t.Setenv("AWS_PROFILE", "ambient")
+
+ headers, err := configHeaders(t, &icebergProvider{sigv4:
&sigv4Config{profile: "named"}})
+ require.NoError(t, err)
+
+ assert.Regexp(t,
`Credential=NAMEDKEY/\d{8}/eu-central-1/execute-api/aws4_request`,
+ headers.Get("Authorization"), "the configured profile wins over
AWS_PROFILE and supplies the region")
+}
+
+func TestNewCatalogRejectsUnknownProfile(t *testing.T) {
+ isolateAWSEnv(t)
+
+ _, err := configHeaders(t, &icebergProvider{sigv4:
&sigv4Config{profile: "missing", region: "us-east-1"}})
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "missing")
+}