Authorization (OAuth 2.0)
OAuth 2.0 is an authorization framework that uses authorization tokens to obtain access to HTTP resources. OAuth 2.0 can be used to check if a consumer is allowed to access a particular URI on the producer.
OAuth 2.0 provides a mechanism to achieve these access permissions in a distributed system by passing signed tokens with every request. Figure 1 shows OAuth 2.0 passing signed tokens with each request, among the NRF, SMF, and CHF.
- The NF Consumer requests an OAuth Token from the NRF, using TLS mAuth to authenticate itself.
- The NRF returns a token, signed with its private key, which includes a list NF services (scopes) that the NF consumer is allowed to access.
- The NF consumer sends the token in the authorization header of an HTTP request to the NF producer.
- The NF producer verifies the token using the pre-installed NRF certificate to ensure it was created by the NRF and has not been modified. It matches a scope in the token to the service being accessed to authorize the request.
HMAC versus RSA
The token can be signed using a shared secret (HMAC) or a public/private key pair (RSA). The token must be signed so that the NF producer can verify that it was produced by the NRF and has not been modified. If HMAC is used, the shared secret must be configured on the NRF and on every NF producer and consumer. Note the following requirements when generating keys:
- The key must be at least 32 bytes long.
- The key must be configured using a secure mechanism, such as Kubernetes Secrets.
- SBA Gateway supports plain-text keys or Base64-encoded keys.
If RSA is used, the NF producer (for example, SBA Gateway) must be configured with a keystore containing a certificate that is used to verify the received token. Normally, this is the certificate of the NRF. For details, see the discussion about OAuth Certificate Management in MATRIXX 5G Integration.
JWT Overview
SBA Gateway validates signed tokens received in JSON Web Token (JWT) format. The standard JWT consists of a header, payload, and payload definitions. An encoded JSON Web Token is passed to an NF producer in the authorization header:
Authorization: Bearer <token>
SBA OAuth Error Responses
If OAuth fails for any reason, SBA Gateway returns the error response defined in RFC 6749 5.2. SBA returns a 400 Bad Request HTTP status code with a JSON body containing an error and error_description, for example:
HTTP/1.1 400 Bad Request
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache
{
"error":"invalid_request",
"error_description":"Authorization header with a single Bearer token required"
}
SBA Authorization Logic
The Figure 2 shows that a Network Function consumer (such as the SMF) must request an access token from the NRF (as per 3GPP TS 33.501). The SMF needs this access token from the NRF before it can send requests to other Network Functions.
The Figure 3 shows that if a token is granted, it is passed in a request to an NF Service.
An NF producer (SBA-GW) authorizes a request against a JSON Web Token using the rules defined in 3GPP TS 33.501 13.4.1. If the request succeeds, it executes the requested service. The following actions occur to the fields in the access token. Note that a JWT payload has a set of claims.
- If the authorization header is missing or does not contain a bearer entry, then an invalid_request error is returned.
- If the authorization header does not contain the expected Bearer <token> format, then an invalid_request error is returned.
- If the token has expired, is malformed, or otherwise invalid, then an invalid_grant error is returned.
- If RSA is used, check that the identity of the issuer of the access token (NRF) in the issuer claim in the access token matches the subject in the NRF certificate from the keystore. Return an invalid_grant error on failure.
- If mTLS is enabled, check that the subject claim within the access token matches the subject in the NF consumer certificate. Return an invalid_grant error on failure.
- Check that the audience claim in the access token matches our own identity
(
nfInstanceId
from the configuration file) or the type of NF service producer (nfType
from the configuration file). - If scope is present, it checks that the scope matches the requested service operation.
SBA Gateway expects the claims as defined in the 3GPP Technical Specification 29.510. For more information, see Definition of type AccessTokenClaims in 3GPP TS 29.510.
{
"iss": "964d462e-bf1b-4a1d-b6d0-f66633aead06",
"sub": "a2953918-0881-4071-a48c-aa774b230d29",
"aud": "CHF",
"scope": "nchf-convergedcharging nchf-spendinglimitcontrol",
"exp": 1565274257
}
- iss — Issuer is the NF instance ID of the NRF.
- sub — Subject is the NF instance ID of the SMF.
- aud — The NF type of the producer (CHF). NF types are defined in 3GGP TS 29.510 6.1.6.3.3.
- scope — The name of the NF services the access token is authorized to use. This is space delimited, and service names are defined in 3GPP TS 29.510 6.1.3.11.
- exp — NumericDate is the value of when the token expires.