Story 05 · The auth plane
Share a stream and a service between accounts
This guide shows you how to export a stream and a service from one account and import both into another.
The auth controller signs the exports and imports into the JWTs of both accounts.
In the manifests, the account monitoring publishes check results and answers execute requests, and the account core imports both.
Before you begin#
You need the NATS operator demo, its NATS cluster demo and the auth controller’s connection from Put a NATS cluster under a NATS operator.
Declare the exports#
Apply the account monitoring with two exports:
check-results, a stream export. It sets noaccess, so any account can import it.execute, a service export withaccess: Private. Only the accounts underimporterscan import it, and the auth controller signs an activation token for each of them.
apiVersion: auth.nats-operator.io/v1beta1
kind: NatsAccount
metadata:
name: monitoring
namespace: nats-system
spec:
operatorRef:
name: demo
exports:
- name: check-results
type: Stream
subject: "monitoring.results.>"
- name: execute
type: Service
subject: "monitoring.execute"
responseType: Singleton
access: Private
importers:
- kind: NatsAccount
name: core
kubectl apply -f https://nats-operator.io/docs/stories/05-account-wiring/01-exporter.yamlExport in the API reference lists the fields of an export and their defaults.
Declare the imports#
Apply the account core.
Each import refers to an account and to the name of an export.
The subject and the type come from the export.
apiVersion: auth.nats-operator.io/v1beta1
kind: NatsAccount
metadata:
name: core
namespace: nats-system
spec:
operatorRef:
name: demo
imports:
- accountRef:
kind: NatsAccount
name: monitoring
export: check-results
localSubject: "upstream.results.>"
- accountRef:
kind: NatsAccount
name: monitoring
export: execute
kubectl apply -f https://nats-operator.io/docs/stories/05-account-wiring/01-importer.yamllocalSubject sets the subject that the import has in core.
Without it, the import keeps the exported subject.
To import from an account in another namespace, the namespace of the exporting account needs a NatsReferenceGrant that admits the importing NatsAccount, as in Let a team declare its own users and streams.
Check the imports#
Read the status of core:
kubectl -n nats-system get natsaccount core -o yamlThe status in the output is similar to this:
status:
observedGeneration: 1
conditions:
- type: Ready
status: "True"
reason: Distributed
- type: ReferencesResolved
status: "True"
reason: AllImportsResolved
imports:
- export: monitoring/check-results
subject: "monitoring.results.>"
localSubject: "upstream.results.>"
type: Stream
- export: monitoring/execute
subject: "monitoring.execute"
type: Service
activation: Signed
distribution:
servers: 3
current: 3
imports lists the subject and the type of each import.
For the private export, activation is Signed.
Exports and imports in the design describes the rules.