Reference

AddTraxAwsSecretsAsync

Package Trax.Effect.Configuration.AwsNamespace Trax.Effect.Configuration.AwsSource TraxAwsSecretsExtensions.cs

Reads a host's secrets from AWS Secrets Manager into its configuration before the host is built, with the credentials the process already has. On EKS that is the Pod Identity role trax deploy gives the pod, so the values never become Kubernetes Secrets and never pass through the cluster's store. It is in its own package, so the AWS SDK reaches only the hosts that reference it.

Signature

public static class TraxAwsSecretsExtensions
{
    public const string Section = "Trax:AwsSecrets";
    public const string SourceName = "aws-secrets";
 
    public static Task<IConfigurationManager> AddTraxAwsSecretsAsync(
        this IConfigurationManager configuration,
        IAmazonSecretsManager? client = null,
        CancellationToken cancellationToken = default
    );
}

Parameters

ParameterWhat it is
configurationThe host builder's configuration (builder.Configuration).
clientThe Secrets Manager client. Null builds one from the process's credentials and region, the usual AWS SDK chain.
cancellationTokenStops the reads.

Behavior

Call it before the host is built:

var builder = WebApplication.CreateBuilder(args);
await builder.Configuration.AddTraxAwsSecretsAsync();

It reads the entries under Trax:AwsSecrets, which trax deploy writes into the pod's environment. Each has:

FieldWhat it means
SecretIdThe secret's name or ARN. Required.
JsonKeyWhen the secret is a JSON object, the property to read (password of an RDS secret).
KeyThe configuration key the value is set under: Stripe:ApiKey, or Stripe__ApiKey as an environment variable names it.
PasswordOfIn place of Key: a connection string name. The value is set as the Password of ConnectionStrings:<name>, quoted, so a ; or ' in it cannot cut the string.
Trax__AwsSecrets__0__SecretId=orders-staging/app/Stripe__ApiKey
Trax__AwsSecrets__0__Key=Stripe__ApiKey
Trax__AwsSecrets__1__SecretId=arn:aws:secretsmanager:us-east-1:123456789012:secret:rds-orders
Trax__AwsSecrets__1__JsonKey=password
Trax__AwsSecrets__1__PasswordOf=Trax

The values are added above the configuration's other sources, so they win over the environment. A secret two entries read is fetched once. An entry it cannot satisfy (no SecretId, neither Key nor PasswordOf, a JSON property the secret lacks, a connection string that is not set) throws InvalidOperationException naming the entry, and so does a secret the role may not read.

Under --trax-export-deploy it reads nothing, so an export needs no AWS credentials. Either way it marks Trax:Deploy:SecretSources:aws-secrets in the configuration, which the host's DeployManifest reports as secretSources: ["aws-secrets"]. A Kubernetes environment on EKS refuses a host whose manifest lacks it.

See also