SetAuthorization decides what the backend sees in the Authorization header. This post runs each mode against a backend that echoes back the headers it received, so you can read the result instead of trusting the description.

The companion posts cover the invoke policy and the switch policy.

The test project

One API Studio project, one API called nano-authz, one operation per mode. Every operation calls the same backend. Its /echo path returns the request headers it received as JSON.

ExtractIdentity, Authenticate and Authorize check the caller’s client credentials first. Then a SetAuthorization policy runs, then an invoke. The order matters. The security triple decides whether the caller gets in. SetAuthorization only decides what the backend is told.

Every call goes to the published product URL with the client credentials of a subscribed application:

curl -s \
  -H "X-IBM-Client-Id: <client-id>" \
  -H "X-IBM-Client-Secret: <client-secret>" \
  "https://<product>-<catalog>-<org>.nanogw.<ingress-domain>/1.0.0/nano-authz/basic/static"

I trimmed the echo responses to the authorization header. The rest of each response is the backend’s own header list.

The policy takes one of four options: basic, oauth, jwt or anonymous. message says which message gets the header. Use request, so the invoke sends it to the backend.

Example 1: Basic credentials from literals

The gateway holds the upstream credential and the caller never sees it. basic.jsonata takes a username and an optional password. Both are JSONata expressions, and the policy builds and encodes the pair for you.

kind: SetAuthorization
spec:
  message: request
  basic:
    jsonata:
      username: "'svc-portal'"
      password: "'<upstream-password>'"

The inner single quotes are part of the value. Without them JSONata reads svc-portal as a path, not a string.

The backend received:

"authorization": "Basic <base64 of svc-portal:<upstream-password>>"

My project file wrote this as static with valueType: jsonata, and the build turned it into the jsonata form above. The reference page documents jsonata, so use that.

Unquoted literals are the quiet failure in this policy. From my project notes, not re-run for this post: the header comes out as Basic Og==, an empty pair, and the status is still 200. Check the decoded header, not the status code.

Example 2: derive the credential from the caller

The caller sends an API key. The gateway turns it into the Basic credential a legacy backend insists on:

kind: SetAuthorization
spec:
  message: request
  basic:
    jsonata:
      username: "$header('request', 'X-Api-Key')"
      password: "'<upstream-password>'"
curl ... -H 'X-Api-Key: team-42' "https://<gateway-host>/1.0.0/nano-authz/basic/mint"

The backend received:

"authorization": "Basic <base64 of team-42:<upstream-password>>"
"x-api-key": "team-42"

I decoded the header to check it. The username is team-42 and the password is the literal from the policy. The caller’s X-Api-Key was passed through too. Strip it if the backend should not see it.

The upstream password is not the caller’s secret, so you can rotate it on the gateway without touching a client.

Now the same call with no X-Api-Key:

HTTP/2 500

Internal Server Error

A missing header is a client mistake, and the gateway reports it as a server error. If you want a clean 4xx, check the header with a switch or if before this policy runs.

Example 3: forward the caller’s Basic credential

useIncoming copies the caller’s Authorization header onto the message. Nothing is stored in the gateway and nothing is decoded. The backend authenticates the caller.

kind: SetAuthorization
spec:
  message: request
  basic:
    useIncoming: {}

The empty map is the whole option. It is a marker, not a setting.

curl ... -H 'Authorization: Basic Y2FsbGVyOnBhc3M=' "https://<gateway-host>/1.0.0/nano-authz/basic/pass-through"
"authorization": "Basic Y2FsbGVyOnBhc3M="

This mode is strict about the scheme:

The caller sends Result
Authorization: Basic ... forwarded unchanged, 200
Authorization: Bearer ... 400 Bad Request
no Authorization header 500 Internal Server Error

Use it when only the backend can verify the credential. It is the right choice if you do not want the gateway holding secrets.

Example 4: forward a JWT

jwt.useIncoming forwards a JSON Web Token and checks that it has the shape of one:

kind: SetAuthorization
spec:
  message: request
  jwt:
    useIncoming: {}
curl ... -H 'Authorization: Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJhbGljZSIsInNjb3BlIjoicmVhZCJ9.' \
  "https://<gateway-host>/1.0.0/nano-authz/bearer/jwt"
"authorization": "Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJzdWIiOiJhbGljZSIsInNjb3BlIjoicmVhZCJ9."

The token came through unchanged. The gateway did not re-sign it and did not check the signature. Signature checking is the job of the security policies earlier in the assembly.

Now an opaque token on the same operation:

curl ... -H 'Authorization: Bearer opaque-token-123' "https://<gateway-host>/1.0.0/nano-authz/bearer/jwt"
HTTP/2 400

Bad Request

Example 5: forward an opaque OAuth token

oAuth2.useIncoming is the same forward without the shape check:

kind: SetAuthorization
spec:
  message: request
  oAuth2:
    useIncoming: {}
curl ... -H 'Authorization: Bearer opaque-token-123' "https://<gateway-host>/1.0.0/nano-authz/bearer/oauth"
"authorization": "Bearer opaque-token-123"

Use oAuth2 when the upstream issues its own token format and only it can judge the token. Use jwt when you want a malformed token to fail at the edge. The forwarded header is identical in both. Both need the Bearer scheme. A Basic header sent to this operation returned 400.

Example 6: strip the header

anonymous removes the header. The caller authenticated with a Basic credential. The backend gets nothing:

kind: SetAuthorization
spec:
  message: request
  anonymous: {}
curl ... -H 'Authorization: Basic Y2FsbGVyOnBhc3M=' "https://<gateway-host>/1.0.0/nano-authz/strip"

The echo’s header list had no authorization key at all. It was not empty. It was absent.

anonymous does not skip authentication. ExtractIdentity, Authenticate and Authorize still ran, so the caller still needs a valid subscription. It only changes what the backend is told.

Use it when the token in hand is scoped to the gateway and the backend should never see it.

Summary

  • Forward with useIncoming when the backend is the only party that can verify the credential.
  • Mint with basic.jsonata when the backend wants a credential the caller does not hold.
  • Use anonymous when the backend is trusted by network policy.
  • A missing source header is a 500 in the mint and forward modes, so guard it before the policy.

Limitations and Notes

  • Tested on a DataPower Nano Gateway with the API Connect 12.1 documentation set. Check the version you run.
  • Not tested: basic.secret, which reads the credential from a Kubernetes Secret. The reference says it is named in the policy. From my project notes, it resolves when the runtime starts and the Secret must be in the gateway runtime’s namespace. This is the production answer for a fixed upstream credential.
  • message: response writes the header on the reply to the caller. I did not test it.
  • I did not look at the gateway log, so I cannot say what it records for the 400 and 500 cases.