# 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](https://nats-operator.io/docs/stories/02-auth-plane/index.md).

## Declare the exports

Apply the account `monitoring` with two exports:

- `check-results`, a stream export.
  It sets no `access`, so any account can import it.
- `execute`, a service export with `access: Private`.
  Only the accounts under `importers` can import it, and the auth controller signs an activation token for each of them.

`01-exporter.yaml`

```yaml
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
```

```sh
kubectl apply -f https://nats-operator.io/docs/stories/05-account-wiring/01-exporter.yaml
```


[Export](https://nats-operator.io/docs/reference/api/index.md#Export) 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.

`01-importer.yaml`

```yaml
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
```

```sh
kubectl apply -f https://nats-operator.io/docs/stories/05-account-wiring/01-importer.yaml
```


`localSubject` 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](https://nats-operator.io/docs/stories/04-team-self-service/index.md).

## Check the imports

Read the status of `core`:

```sh
kubectl -n nats-system get natsaccount core -o yaml
```

The `status` in the output is similar to this:

`01-status-natsaccount-core.yaml`

```yaml
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](https://nats-operator.io/docs/design/v1/index.md#54-exports-and-imports) in the design describes the rules.

