Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
e3bea2f
Add mTLS and OAuth authentication to event REST API
jzding Aug 26, 2025
513e769
clean up server/client AuthConfig struct
jzding Oct 2, 2025
68a37aa
Update Swagger documentation with comprehensive authentication support
jzding Oct 8, 2025
93b8a73
add oran doc
jzding Nov 17, 2025
280bc42
Add mTLS and OAuth authentication documentation to O-RAN specification
jzding Nov 17, 2025
1f75025
remove Openshift specific details in oran docs
jzding Dec 12, 2025
da663fa
Enforce mTLS+OAuth on all APIs, TokenReview validation, TLS profile
jzding Sep 9, 2026
6aaccdb
Export ApplyTLSProfile for client-side TLS profile reuse
jzding Sep 9, 2026
7f73e7b
Fix gosec G402 and harden endpoint SSRF at dial time
jzding Sep 9, 2026
65ede7d
test: fix gosec G402 lint and remove committed store artifacts
jzding Sep 10, 2026
6fe1192
test: fix double-slash CurrentState URLs breaking with no-redirect cl…
jzding Sep 10, 2026
ac22e28
Address PR #113 review: SSRF-harden initial POST, fail-closed CA, doc…
jzding Sep 10, 2026
9688905
v2/server: remove unauthenticated debug echo handler at base path
jzding Sep 10, 2026
18cd3ed
v2/server: add WriteTimeout, IdleTimeout, MaxHeaderBytes hardening
jzding Sep 10, 2026
c6e15b6
v2: bound request-body reads and clarify conditional auth in swagger
jzding Sep 10, 2026
87df14c
v2: authenticate outbound pushes under mTLS and OAuth
jzding Oct 1, 2026
a7ed0a0
CNF-26787: document outbound push-leg client authentication
jzding Oct 1, 2026
2b399ca
CNF-26787: fix push-leg auth review findings and lint
jzding Oct 1, 2026
b54cbdc
CNF-26787: satisfy goconst and govet shadow linters
jzding Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
cover.out
pub.json
sub.json
# Per-clientID subscription store files written by tests (storePath ".")
v2/????????-????-????-????-????????????.json

.idea
.cache
Expand Down
480 changes: 480 additions & 0 deletions AUTHENTICATION.md

Large diffs are not rendered by default.

362 changes: 362 additions & 0 deletions OPENSHIFT_AUTHENTICATION.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@

The REST-API specification below is generated by Swagger tools. Please refer to the [Developers Guide](docs/dev-readme.md) on how to use Swagger to generate specs and documentations.

## Authentication

This REST API supports enterprise-grade authentication using mTLS and OAuth with **strict security validation**. For detailed configuration instructions, see:

- **[Authentication Configuration](AUTHENTICATION.md)** - Complete guide for configuring mTLS and OAuth authentication
- **[OpenShift Authentication](OPENSHIFT_AUTHENTICATION.md)** - OpenShift-specific deployment guide with native Service CA and OAuth server integration

### Security Features

- **Server-side OAuth Validation**: Bearer tokens are validated by the Kubernetes TokenReview API (issuer, signature, expiry, audience) with no bypass mechanisms
- **Audience Binding**: `requiredAudiences` ensures tokens minted for other services are rejected
- **Expiration Checking**: Expired tokens are rejected by TokenReview
- **mTLS Certificate Validation**: Client certificates are verified against the configured CA
- **SSRF Hardening**: Caller-supplied endpoint URIs are validated (resolve-then-connect, no redirects) before the server dials them

### Recent Security Improvements

- **TokenReview-based OAuth**: Token validation is delegated to the Kubernetes API server; the library performs no local JWT parsing or JWKS fetching
- **Bounded Token Cache**: Validated results are cached briefly with a short TTL to bound TokenReview load
- **Enhanced Error Handling**: Clear error messages for authentication failures without exposing sensitive information

## O-RAN Compliant REST API Specification

Starting from release [v1.21.0](https://github.com/redhat-cne/rest-api/releases/tag/v1.21.0), the REST API implemented in this repo is compliant with [O-RAN O-Cloud Notification API Specification for Event Consumers 4.0](https://orandownloadsweb.azurewebsites.net/specifications).
Expand Down
14 changes: 14 additions & 0 deletions auth-config-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"enableMTLS": true,
"caCertPath": "/etc/certs/ca.crt",
"serverCertPath": "/etc/certs/server.crt",
"serverKeyPath": "/etc/certs/server.key",

"enableOAuth": true,
"requiredAudiences": ["https://kubernetes.default.svc"],
"serviceAccountName": "cloud-event-proxy-sa",
"serviceAccountToken": "/var/run/secrets/kubernetes.io/serviceaccount/token",

"tlsMinVersion": "VersionTLS12",
"tlsCipherSuites": []
}
72 changes: 72 additions & 0 deletions docs/dev-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,36 @@ Open https://editor.swagger.io/ in a browser. Click `File` - `Import file` from

![Alt text](swagger-editor.png "Swagger Editor")

The updated Swagger specification includes:

- **Authentication Documentation**: Comprehensive mTLS and OAuth 2.0 security definitions
- **Enhanced API Descriptions**: Detailed endpoint descriptions with authentication requirements
- **Security Schemes**: Proper documentation of dual authentication (mTLS + OAuth)
- **Error Responses**: Complete 401 Unauthorized responses for protected endpoints
- **Tags and Categories**: Organized endpoints by functionality (Subscriptions, Publishers, Events, HealthCheck, Authentication)

### Interact with REST-API in Swagger UI

You can interact with API endpoint by click `Try it out`, enter required parameters and click `Execute`.
This requires a REST-API server to be deployed at backend and accessible from localhost.

**Important**: When testing authenticated endpoints, you must:

1. **Configure mTLS**: Set up client certificates in your HTTP client
2. **Provide OAuth Token**: Include valid Bearer token in Authorization header
3. **Use HTTPS**: Ensure secure connection for mTLS authentication

Example authentication setup:
```bash
# For mTLS
--cert /path/to/client.crt \
--key /path/to/client.key \
--cacert /path/to/ca.crt \

# For OAuth
-H "Authorization: Bearer your_jwt_token_here"
```

## Generate Swagger Spec

The swagger documentation of this repo is generated using tools and annotations based on https://github.com/go-swagger/go-swagger. The current version of go-swagger has an issue of generating empty definitions with go 1.20+. The workaround is to run swagger tool from docker.
Expand All @@ -32,6 +57,12 @@ SWAGGER_GENERATE_EXTENSION=false swagger generate spec --input tags.json -o swag
swagger validate swagger.json
```

**Note**: The swagger.json file has been enhanced with:
- Security definitions for mTLS and OAuth 2.0
- Authentication requirements for protected endpoints
- Comprehensive error response documentation
- Updated API descriptions and metadata

## Generate REST API Documentation

Use the following commands to generate swagger documentation markdown file [rest_api_v2.md](rest_api_v2.md).
Expand All @@ -41,3 +72,44 @@ Use the following commands to generate swagger documentation markdown file [rest
cd $WORKSPACE/redhat-cne/rest-api/v2
swagger generate markdown --skip-validation --output=../docs/rest_api_v2.md
```

The generated documentation includes:

- **Security Model**: Complete authentication and authorization documentation
- **Endpoint Reference**: All endpoints with authentication requirements
- **Request/Response Examples**: Sample payloads and responses
- **Error Handling**: Comprehensive error response documentation
- **Authentication Guide**: mTLS and OAuth integration examples

## Authentication Testing

When testing the API with authentication enabled:

### mTLS Testing
```bash
curl -X POST https://localhost:9043/api/ocloudNotifications/v2/subscriptions \
--cert /path/to/client.crt \
--key /path/to/client.key \
--cacert /path/to/ca.crt \
-H "Content-Type: application/json" \
-d '{"EndpointUri": "http://example.com/callback", "ResourceAddress": "/test/resource"}'
```

### OAuth Testing
```bash
curl -X POST https://localhost:9043/api/ocloudNotifications/v2/subscriptions \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{"EndpointUri": "http://example.com/callback", "ResourceAddress": "/test/resource"}'
```

### Dual Authentication Testing
```bash
curl -X POST https://localhost:9043/api/ocloudNotifications/v2/subscriptions \
--cert /path/to/client.crt \
--key /path/to/client.key \
--cacert /path/to/ca.crt \
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..." \
-H "Content-Type: application/json" \
-d '{"EndpointUri": "http://example.com/callback", "ResourceAddress": "/test/resource"}'
```
Binary file added docs/oran.docx
Binary file not shown.
Loading
Loading