Account Imports and Exports
Since v0.7.0:
AccountExportandAccountImportare released NAuth APIs for declaring account-to-account subject sharing.
An AccountExport declares subjects offered by an exporting Account. An
AccountImport declares the subjects consumed by an importing Account and
references the exporting Account. NAuth validates both resources and adds
their normalized claims to the corresponding account JWTs.
Prerequisites
Section titled “Prerequisites”Install NAuth and create a ready NatsCluster first. The manifests below use
the NatsCluster from the Getting Started guide:
nauth/example-nats-cluster. Replace that reference with the cluster used by
your installation if it differs.
The complete runnable scenario is available in the repository’s account-import-export example.
Create the accounts
Section titled “Create the accounts”Create one account that exports a subject and one account that imports it:
apiVersion: v1kind: Namespacemetadata: name: my-team---apiVersion: nauth.io/v1alpha1kind: Accountmetadata: name: export-account namespace: my-teamspec: natsClusterRef: namespace: nauth name: example-nats-cluster---apiVersion: nauth.io/v1alpha1kind: Accountmetadata: name: import-account namespace: my-teamspec: natsClusterRef: namespace: nauth name: example-nats-clusterSave the manifest as accounts.yaml and apply it:
kubectl apply -f accounts.yamlkubectl wait --for=condition=Ready account/export-account account/import-account \ --namespace my-team --timeout=120sDeclare the export
Section titled “Declare the export”An AccountExport belongs to the exporting account through
spec.accountName. Each export must contain at least one rule with a subject
and an export type, either stream or service.
apiVersion: nauth.io/v1alpha1kind: AccountExportmetadata: name: shared-subjects namespace: my-teamspec: accountName: export-account rules: - name: shared-stream subject: shared.> type: streamSave this as account-export.yaml and apply it:
kubectl apply -f account-export.yamlkubectl wait --for=condition=Ready accountexport/shared-subjects \ --namespace my-team --timeout=120sDeclare the import
Section titled “Declare the import”An AccountImport belongs to the importing account through
spec.accountName. spec.exportAccountRef points to the exporting
Account, not to an AccountExport. The namespace defaults to the importing
account’s namespace; set it explicitly for a cross-namespace export account.
The imported subject must be identical to or a subset of the exported
subject. The type must also match the intended NATS stream or service
workflow.
apiVersion: nauth.io/v1alpha1kind: AccountImportmetadata: name: shared-subjects namespace: my-teamspec: accountName: import-account exportAccountRef: name: export-account namespace: my-team rules: - name: shared-stream subject: shared.> type: streamSave this as account-import.yaml and apply it:
kubectl apply -f account-import.yamlkubectl wait --for=condition=Ready accountimport/shared-subjects \ --namespace my-team --timeout=120sVerify the resulting claims
Section titled “Verify the resulting claims”Inspect the resource conditions when troubleshooting validation or account binding:
kubectl get account,accountexport,accountimport -n my-teamkubectl get accountexport shared-subjects -n my-team -o jsonpath='{.status.conditions}'kubectl get accountimport shared-subjects -n my-team -o jsonpath='{.status.conditions}'AccountExport reports ValidRules, BoundToAccount,
AdoptedByAccount, and Ready conditions. AccountImport reports
BoundToAccount, BoundToExportAccount, ValidRules, AdoptedByAccount,
and Ready conditions. The normalized claims are available under
status.desiredClaim on each child resource and under the corresponding
account’s status.claims after account reconciliation:
kubectl get account export-account -n my-team \ -o jsonpath='{.status.claims.exports}'kubectl get account import-account -n my-team \ -o jsonpath='{.status.claims.imports}'If either referenced account is missing or not ready, or a rule is invalid,
the child resource remains not ready and its conditions explain what NAuth is
waiting for. Keep the export and import subjects aligned manually: the
current AccountImport implementation validates the referenced accounts and
import rules, but does not compare an import with a specific AccountExport
resource or enforce exporter-side policy.
Current limitations
Section titled “Current limitations”The AccountExport and AccountImport child CRDs do not currently expose
NATS activation-token fields. This walkthrough therefore covers public
stream and service exports only; activation-token issuance and distribution
are not implemented in this workflow.