Skip to content

Commit 1851e03

Browse files
Merge pull request #120 from kuudori/HYPERFLEET-492
HYPERFLEET-492 - refactor: replace OCM auth client with JWT-based auth
2 parents 60956b9 + 3fc8716 commit 1851e03

52 files changed

Lines changed: 1014 additions & 1514 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AGENTS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ make generate-all # Both of the above
3636
```
3737
make verify # go vet + gofmt check
3838
make lint # golangci-lint
39-
make test # Unit tests (OCM_ENV=unit_testing)
40-
make test-integration # Integration tests with testcontainers (OCM_ENV=integration_testing)
39+
make test # Unit tests (HYPERFLEET_ENV=unit_testing)
40+
make test-integration # Integration tests with testcontainers (HYPERFLEET_ENV=integration_testing)
4141
make test-helm # Helm chart lint + template validation
4242
make verify-all # verify + lint + test — fast, no DB needed
4343
make test-all # lint + test + test-integration + test-helm — full suite
@@ -54,9 +54,9 @@ Run `make help` for the complete target list.
5454

5555
## Testing
5656

57-
**Unit tests**: `make test` — sets `OCM_ENV=unit_testing`, runs `./pkg/...` and `./cmd/...`
57+
**Unit tests**: `make test` — sets `HYPERFLEET_ENV=unit_testing`, runs `./pkg/...` and `./cmd/...`
5858

59-
**Integration tests**: `make test-integration` — sets `OCM_ENV=integration_testing` and `TESTCONTAINERS_RYUK_DISABLED=true`. Testcontainers auto-creates isolated PostgreSQL instances. Located in `test/integration/`.
59+
**Integration tests**: `make test-integration` — sets `HYPERFLEET_ENV=integration_testing` and `TESTCONTAINERS_RYUK_DISABLED=true`. Testcontainers auto-creates isolated PostgreSQL instances. Located in `test/integration/`.
6060

6161
**Helm tests**: `make test-helm` — lints and renders templates with multiple value combinations.
6262

@@ -67,7 +67,7 @@ Run `make help` for the complete target list.
6767
**Integration test setup**: `test.RegisterIntegration(t)` returns `(helper, client)`. Uses Gomega assertions and Resty HTTP client.
6868

6969
**Environment variables for tests**:
70-
- `OCM_ENV` — selects config: `unit_testing`, `integration_testing`, `development`
70+
- `HYPERFLEET_ENV` — selects config: `unit_testing`, `integration_testing`, `development`
7171
- `TESTCONTAINERS_RYUK_DISABLED=true` — required in CI
7272
- `HYPERFLEET_CLUSTER_ADAPTERS` / `HYPERFLEET_NODEPOOL_ADAPTERS` — adapter lists (defaults set in TestMain)
7373

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- JWT authentication handler using `golang-jwt/jwt/v5` and `MicahParks/keyfunc/v3` with RS256 validation, configurable issuer and audience, and JWKS key rotation support ([#120](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/120))
1213
- Hard deletion for Clusters and NodePools: resources and their adapter statuses are permanently removed from the database once all required adapters report `Finalized=True` and no child resources remain ([#119](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/119))
1314
- `Finalized` condition aggregation with `WaitingForChildResources` intermediate state when all adapters are finalized but child node pools still exist ([#119](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/119))
1415
- Soft deletion for Clusters and NodePools with `deleted_time` and `deleted_by` fields for tracking deletion requests ([#106](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/106))
@@ -28,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2829

2930
### Changed
3031

32+
- Replaced OCM SDK authentication handler with standalone JWT middleware, removing `ocm-sdk-go` dependency and its transitive dependencies (`glog`, `bluemonday`, `json-iterator`) ([#120](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/120))
33+
- Upgraded JWT library from `golang-jwt/jwt/v4` to `golang-jwt/jwt/v5` ([#120](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/120))
3134
- Refactored `AdapterStatusDao.Upsert()` to accept a pre-fetched existing record, moving lookup and `LastTransitionTime` preservation logic to the service layer ([#119](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/119))
3235
- Refactored DAO methods to remove Unscoped calls for fetching Clusters and NodePools ([#106](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/106))
3336
- Bumped oapi-codegen version to fix missing `omitempty` on generated response objects ([#106](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/106))
@@ -37,6 +40,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3740
- Streamlined configuration system with Viper, removed getters and _FILE suffix pattern ([#75](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/75))
3841
- Used CHANGE_ME placeholder for image registry ([#83](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/83))
3942

43+
### Removed
44+
45+
- OCM SDK dependency (`ocm-sdk-go`), OCM client (`pkg/client/ocm/`), OCM configuration (`pkg/config/ocm.go`), OCM logger bridge (`pkg/logger/ocm_bridge.go`), and OCM authorization mocks ([#120](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/120))
46+
4047
### Fixed
4148

4249
- Validated adapter status conditions in handler layer ([#88](https://github.com/openshift-hyperfleet/hyperfleet-api/pull/88))

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Tool management uses [Bingo](https://github.com/bwplotka/bingo) — tool version
3434
|---|---|---|
3535
| `make verify` | go vet + gofmt check | No |
3636
| `make lint` | golangci-lint | No |
37-
| `make test` | Unit tests (`OCM_ENV=unit_testing`) | No |
37+
| `make test` | Unit tests (`HYPERFLEET_ENV=unit_testing`) | No |
3838
| `make test-integration` | Integration tests (testcontainers) | No (auto-creates) |
3939
| `make test-helm` | Helm chart lint + template validation | No |
4040
| `make verify-all` | verify + lint + test (single command) | No |

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ make test
9696
make ci-test-unit
9797
```
9898

99-
Unit tests run with `OCM_ENV=unit_testing` and do not require a running database.
99+
Unit tests run with `HYPERFLEET_ENV=unit_testing` and do not require a running database.
100100

101101
### Integration Tests
102102
```bash

Makefile

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,19 @@ db_password_file := ${PWD}/secrets/db.password
6565
db_sslmode := disable
6666
db_image ?= docker.io/library/postgres:14.2
6767

68-
# Location of the JSON web key set used to verify tokens
69-
jwks_url := https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/certs
70-
7168
# Test output files
7269
unit_test_json_output ?= ${PWD}/unit-test-results.json
7370
integration_test_json_output ?= ${PWD}/integration-test-results.json
7471

7572
### Environment-sourced variables with defaults
76-
ifndef OCM_ENV
77-
OCM_ENV := development
73+
ifndef HYPERFLEET_ENV
74+
HYPERFLEET_ENV := development
7875
endif
7976

8077
ifndef TEST_SUMMARY_FORMAT
8178
TEST_SUMMARY_FORMAT = short-verbose
8279
endif
8380

84-
ifndef OCM_BASE_URL
85-
OCM_BASE_URL := "https://api.integration.openshift.com"
86-
endif
8781

8882
.PHONY: help
8983
help: ## Display this help
@@ -154,7 +148,7 @@ run: build ## Run the application
154148
.PHONY: run-no-auth
155149
run-no-auth: build ## Run the application without auth
156150
./bin/hyperfleet-api migrate
157-
./bin/hyperfleet-api serve --enable-authz=false --enable-jwt=false
151+
./bin/hyperfleet-api serve --server-jwt-enabled=false
158152

159153
.PHONY: run/docs
160154
run/docs: check-container-tool ## Run swagger and host the api spec
@@ -191,33 +185,31 @@ secrets: ## Initialize secrets directory with default values
191185
@printf "$(db_password)" > secrets/db.password
192186
@printf "$(db_port)" > secrets/db.port
193187
@printf "$(db_user)" > secrets/db.user
194-
@printf "ocm-hyperfleet-testing" > secrets/ocm-service.clientId
195-
@printf "your-client-secret-here" > secrets/ocm-service.clientSecret
196-
@printf "your-token-here" > secrets/ocm-service.token
188+
197189
@echo "Secrets directory initialized with default values"
198190

199191
##@ Testing
200192

201193
.PHONY: test
202194
test: install secrets $(GOTESTSUM) ## Run unit tests
203-
OCM_ENV=unit_testing $(GOTESTSUM) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -v $(TESTFLAGS) \
195+
HYPERFLEET_ENV=unit_testing $(GOTESTSUM) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -v $(TESTFLAGS) \
204196
./pkg/... \
205197
./cmd/...
206198

207199
.PHONY: ci-test-unit
208200
ci-test-unit: install secrets $(GOTESTSUM) ## Run unit tests with JSON output
209-
OCM_ENV=unit_testing $(GOTESTSUM) --jsonfile-timing-events=$(unit_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -v $(TESTFLAGS) \
201+
HYPERFLEET_ENV=unit_testing $(GOTESTSUM) --jsonfile-timing-events=$(unit_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -v $(TESTFLAGS) \
210202
./pkg/... \
211203
./cmd/...
212204

213205
.PHONY: test-integration
214206
test-integration: install secrets $(GOTESTSUM) ## Run integration tests
215-
TESTCONTAINERS_RYUK_DISABLED=true OCM_ENV=integration_testing $(GOTESTSUM) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
207+
TESTCONTAINERS_RYUK_DISABLED=true HYPERFLEET_ENV=integration_testing $(GOTESTSUM) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
216208
./test/integration
217209

218210
.PHONY: ci-test-integration
219211
ci-test-integration: install secrets $(GOTESTSUM) ## Run integration tests with JSON output
220-
TESTCONTAINERS_RYUK_DISABLED=true OCM_ENV=integration_testing $(GOTESTSUM) --jsonfile-timing-events=$(integration_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
212+
TESTCONTAINERS_RYUK_DISABLED=true HYPERFLEET_ENV=integration_testing $(GOTESTSUM) --jsonfile-timing-events=$(integration_test_json_output) --format $(TEST_SUMMARY_FORMAT) -- -p 1 -ldflags -s -v -timeout 1h $(TESTFLAGS) \
221213
./test/integration
222214

223215
.PHONY: test-all
@@ -329,8 +321,7 @@ test-helm: ## Test Helm charts (lint, template, validate)
329321
--set image.tag=test \
330322
--set 'adapters.cluster=["validation"]' \
331323
--set 'adapters.nodepool=["validation"]' \
332-
--set auth.enableJwt=false \
333-
--set auth.enableAuthz=false > /dev/null
324+
--set config.server.jwt.enabled=false > /dev/null
334325
@echo "Auth disabled config template OK"
335326
@echo ""
336327
@echo "Testing template with custom image..."

PREREQUISITES.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ PostgreSQL client tools provide the `psql` command-line interface for database i
3838
- **Installation**: Follow the instructions on the [jq official website](https://jqlang.github.io/jq/)
3939
- **Verification**: Run `jq --version`
4040

41-
## ocm CLI (Optional)
42-
43-
`ocm` stands for OpenShift Cluster Manager CLI and is used for authentication in production mode.
44-
45-
- **Purpose**: CLI tool for authenticating with OCM and making authenticated API requests
46-
- **Installation**: Refer to the [OCM CLI documentation](https://github.com/openshift-online/ocm-cli)
47-
- **Note**: Only required when running with authentication enabled (production mode)
48-
- **Development**: For local development, use `make run-no-auth` which bypasses authentication
49-
5041
## Quick Verification
5142

5243
Run these commands to verify all prerequisites are installed:
@@ -57,9 +48,6 @@ go version # Should show 1.24 or higher
5748
podman --version
5849
psql --version # PostgreSQL client
5950
jq --version # JSON processor
60-
61-
# Optional tools
62-
ocm version # OCM CLI (production auth only)
6351
```
6452

6553
## Getting Started

charts/templates/configmap.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ data:
2727
2828
jwt:
2929
enabled: {{ .Values.config.server.jwt.enabled }}
30-
31-
authz:
32-
enabled: {{ .Values.config.server.authz.enabled }}
30+
issuer_url: {{ .Values.config.server.jwt.issuer_url | quote }}
31+
audience: {{ .Values.config.server.jwt.audience | quote }}
3332
3433
jwk:
3534
cert_file: {{ .Values.config.server.jwk.cert_file | quote }}
3635
cert_url: {{ .Values.config.server.jwk.cert_url | quote }}
3736
38-
acl:
39-
file: {{ .Values.config.server.acl.file | quote }}
40-
4137
database:
4238
dialect: {{ .Values.config.database.dialect }}
4339

charts/values.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,12 @@ config:
5050

5151
jwt:
5252
enabled: true
53-
54-
authz:
55-
enabled: false
53+
issuer_url: ""
54+
audience: ""
5655

5756
jwk:
5857
cert_file: ""
59-
cert_url: "https://sso.redhat.com/auth/realms/redhat-external/protocol/openid-connect/certs"
60-
61-
acl:
62-
file: ""
58+
cert_url: ""
6359

6460
# Database configuration
6561
database:

cmd/hyperfleet-api/environments/e_development.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func (e *devEnvImpl) OverrideConfig(c *config.ApplicationConfig) error {
2626
c.Database.SSL.Mode = SSLModeDisable
2727
}
2828

29-
// Enable OCM mocks for development (no real OCM connection needed)
30-
c.OCM.Mock.Enabled = true
31-
3229
return nil
3330
}
3431

@@ -40,10 +37,6 @@ func (e *devEnvImpl) OverrideHandlers(h *Handlers) error {
4037
return nil
4138
}
4239

43-
func (e *devEnvImpl) OverrideClients(c *Clients) error {
44-
return nil
45-
}
46-
4740
func (e *devEnvImpl) EnvironmentDefaults() map[string]string {
4841
// Return empty map - new config system has appropriate defaults
4942
// and OverrideConfig() sets development-specific values programmatically

cmd/hyperfleet-api/environments/e_integration_testing.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ func (e *integrationTestingEnvImpl) OverrideConfig(c *config.ApplicationConfig)
3838
c.Database.SSL.Mode = SSLModeDisable
3939
}
4040

41-
// Enable OCM mocks for integration testing (no real OCM connection needed)
42-
c.OCM.Mock.Enabled = true
43-
4441
return nil
4542
}
4643

@@ -52,10 +49,6 @@ func (e *integrationTestingEnvImpl) OverrideHandlers(h *Handlers) error {
5249
return nil
5350
}
5451

55-
func (e *integrationTestingEnvImpl) OverrideClients(c *Clients) error {
56-
return nil
57-
}
58-
5952
func (e *integrationTestingEnvImpl) EnvironmentDefaults() map[string]string {
6053
// Return empty map - new config system has appropriate defaults
6154
// and OverrideConfig() sets test-specific values programmatically

0 commit comments

Comments
 (0)