Skip to content

@aws-sdk/credential-providers has trouble reading config files from home-relative paths #5876

@jbreckmckye

Description

@jbreckmckye

Describe the bug

I think there may be a bug with the SSO credentials library, or in its chain of dependencies. I'm raising the issue here as this is the SDK actually affected.

When using the fromSSO function, if I pass a home-relative path string toconfigFilepath, loading the credentials from ambient INI files fails. For example ~/.aws.config as opposed to /Users/jbreckmckye/.aws/config

If I pass a root-relative path to the same file, or omit the configFilepath, it works fine and picks up the credentials from the ini.

Expected Behavior

Expected: to retrieve the credentials already set up with aws sso login --profile MyProfileName, by using the files populated already in ~/.aws/credentials, ~/.aws/config

Current Behavior

The SDK throws a CredentialsProviderError due to, it seems, being unable to load un-path-resolved files

Reproduction Steps

import { fromSSO } from '@aws-sdk/credential-providers'
import { S3Client, ListBucketsCommand } from '@aws-sdk/client-s3'

async function main() {
  const client = new S3Client({
    region: 'eu-west-1',
    credentials: fromSSO({
      profile: 'EngineerBeta',
      filepath: '~/.aws/credentials',
      configFilepath: '~/.aws/config', // works IF this is omitted, OR is the `realpath` of this same file
    }),
  } as any)

  const cmd = new ListBucketsCommand({})

  await client.send(cmd as any)
}

The ENV_CONFIG_PATH env var is unset.

I was able to trace the code as far as Smithy's loadSharedConfigFiles function:

  • I found that configFile and credentialsFile are resolved to their root-relative paths in the 'good' cases
  • but they are left as unresolved ~/.aws/... home-relative paths specifically when configFilepath is a home-relative path

Possible Solution

I wasn't able to trace the logic further than the shared-ini-file-loader package in the Smithy namespace.

Additional Information/Context

No response

SDK version used

@aws-sdk/credential-providers version 3.509.0

Environment details (OS name and version, etc.)

MacOS Sonoma

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.p3This is a minor priority issuequeuedThis issues is on the AWS team's backlog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions