Skip to content

Commit 3fae9c4

Browse files
committed
Add READMEs for new credential packages
1 parent 9a4acf8 commit 3fae9c4

3 files changed

Lines changed: 192 additions & 0 deletions

File tree

aws/aws-config/README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# AWS Config
2+
3+
Parses AWS shared configuration files (`~/.aws/config` and `~/.aws/credentials`) and resolves credentials from profiles.
4+
5+
## Dependency
6+
7+
```kotlin
8+
dependencies {
9+
implementation("software.amazon.smithy.java:aws-config:1.1.0")
10+
}
11+
```
12+
13+
## Usage
14+
15+
Config file-based credential resolution is wired up automatically when
16+
`AwsCredentialChainPlugin` is installed on a client. This module registers
17+
itself in the `SHARED_CONFIG` chain slot via ServiceLoader, so no additional
18+
code is needed beyond adding the dependency.
19+
20+
## Programmatic config file support
21+
22+
You can load and query config files directly:
23+
24+
```java
25+
// Load and query the config file
26+
AwsProfileFile file = AwsProfileFile.load();
27+
AwsProfile profile = file.profile("default");
28+
String region = profile.property("region");
29+
30+
// Resolve credentials from a profile directly
31+
AwsProfileCredentialsResolver resolver = AwsProfileCredentialsResolver.builder()
32+
.profileName("dev")
33+
.build();
34+
35+
IdentityResult<AwsCredentialsIdentity> result = resolver.resolveIdentity(Context.empty());
36+
```
37+
38+
## Supported credential sources
39+
40+
Profiles can define credentials in multiple ways. This module handles:
41+
42+
- **Static keys**`aws_access_key_id` + `aws_secret_access_key`
43+
- **Session keys** — static keys + `aws_session_token`
44+
- **credential_process** — external program that outputs JSON credentials
45+
46+
## Modular credential sources
47+
48+
Additional sources like IMDS, AssumeRole, SSO, WebIdentity, and Login are
49+
detected and typed but require separate handler modules (`aws-credentials-sts`,
50+
`aws-credentials-sso`, etc.) to resolve. When possible, this module detects
51+
if you intended to use one of these providers but are missing the dependency.
52+
53+
## Extensibility
54+
55+
Implement `AwsConfigCredentialSourceHandler` and register via
56+
`META-INF/services` to handle additional source types.

aws/aws-credential-chain/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# AWS Credential Chain
2+
3+
Assembles an ordered AWS credential provider chain from SPI-discovered
4+
providers. Provides the infrastructure for modular credential resolution.
5+
6+
## Dependency
7+
8+
```kotlin
9+
dependencies {
10+
implementation("software.amazon.smithy.java:aws-credential-chain:1.1.0")
11+
}
12+
```
13+
14+
## Wiring to a client
15+
16+
### Automatic (codegen)
17+
18+
Services modeled with `@aws.auth#sigv4` or `@aws.auth#sigv4a` automatically get
19+
`AwsCredentialChainPlugin` added as a default plugin during code generation.
20+
No manual wiring is needed: just add the provider modules you need to your
21+
runtime dependencies.
22+
23+
### Manual
24+
25+
```java
26+
var client = MyClient.builder()
27+
.addPlugin(new AwsCredentialChainPlugin())
28+
.build();
29+
```
30+
31+
The plugin registers the credential chain as the client's identity resolver and
32+
adds an interceptor that invalidates cached credentials on auth failures
33+
(`ExpiredToken`, `InvalidToken`, `AuthFailure`).
34+
35+
## Standalone usage
36+
37+
```java
38+
try (AwsCredentialChain chain = AwsCredentialChain.create()) {
39+
IdentityResult<AwsCredentialsIdentity> result = chain.resolveIdentity(context);
40+
}
41+
```
42+
43+
## How it works
44+
45+
The chain discovers `AwsCredentialProvider` implementations via ServiceLoader,
46+
orders them by builtin enum slots, and tries each in order until one succeeds.
47+
48+
## Builtin slots (in priority order)
49+
50+
1. `CODE` — programmatic
51+
2. `JAVA_SYSTEM_PROPERTIES``aws.accessKeyId`
52+
3. `ENVIRONMENT``AWS_ACCESS_KEY_ID`
53+
4. `WEB_IDENTITY_TOKEN_ENV``AWS_WEB_IDENTITY_TOKEN_FILE` + `AWS_ROLE_ARN`
54+
5. `SHARED_CONFIG``~/.aws/config` / `~/.aws/credentials`
55+
6. `ECS_CONTAINER``AWS_CONTAINER_CREDENTIALS_FULL_URI`
56+
7. `EC2_INSTANCE_METADATA` — IMDS
57+
58+
## Ordering
59+
60+
Providers position themselves relative to builtin slots using
61+
`OrderingConstraint`:
62+
63+
- `Builtin(slot)` — claims a builtin slot (one provider per slot). Only one
64+
provider can claim a builtin. Not all builtins have to be claimed.
65+
- `Before(slot)` — inserts before the given slot's position
66+
- `After(slot)` — inserts after the given slot's position
67+
68+
Before/After reference enum values only, so cycles are impossible. If the
69+
referenced slot has no registered provider, the custom provider is placed
70+
where that slot would be in enum order.
71+
72+
## Adding a custom provider
73+
74+
```java
75+
public class MyProvider implements AwsCredentialProvider {
76+
@Override
77+
public String name() {
78+
return "MyCustomProvider";
79+
}
80+
81+
@Override
82+
public OrderingConstraint ordering() {
83+
return new OrderingConstraint.After(BuiltinProvider.SHARED_CONFIG);
84+
}
85+
86+
@Override
87+
public IdentityResolver<AwsCredentialsIdentity> create(ProviderContext ctx) {
88+
return new MyResolver();
89+
}
90+
}
91+
```
92+
93+
Register in `META-INF/services/software.amazon.smithy.java.aws.credentials.chain.AwsCredentialProvider`.

aws/aws-credentials-imds/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# AWS Credentials IMDS
2+
3+
Credential provider for EC2 instances using the Instance Metadata Service
4+
(IMDSv2).
5+
6+
## Dependency
7+
8+
```kotlin
9+
dependencies {
10+
implementation("software.amazon.smithy.java:aws-credentials-imds:1.1.0")
11+
}
12+
```
13+
14+
## Usage
15+
16+
No code changes are needed. The provider is discovered automatically via
17+
ServiceLoader and claims the `EC2_INSTANCE_METADATA` slot in the credential
18+
chain.
19+
20+
## Behavior
21+
22+
- Uses IMDSv2 exclusively (no v1 fallback)
23+
- Tries the extended API first (`/security-credentials-extended/`), falls back
24+
to legacy on 404
25+
- Caches credentials with background refresh before expiration
26+
- Implements static stability: expired credentials are returned during outages
27+
- Retries with exponential backoff (3 attempts)
28+
29+
## Configuration
30+
31+
Configuration is checked in priority order. The first non-null value wins.
32+
33+
system property > env var > config file
34+
35+
| Source | Key | Effect |
36+
|--------|-----|--------|
37+
| System property | `aws.disableEc2Metadata=true` | Disables IMDS |
38+
| Environment | `AWS_EC2_METADATA_DISABLED=true` | Disables IMDS |
39+
| Config file | `disable_ec2_metadata=true` | Disables IMDS |
40+
| Environment | `AWS_EC2_METADATA_SERVICE_ENDPOINT` | Overrides endpoint (e.g., for IPv6) |
41+
| System property | `aws.ec2InstanceProfileName` | Skips profile discovery |
42+
| Environment | `AWS_EC2_INSTANCE_PROFILE_NAME` | Skips profile discovery |
43+
| Config file | `ec2_instance_profile_name` | Skips profile discovery |

0 commit comments

Comments
 (0)