Skip to content

Commit d53dffb

Browse files
authored
Merge pull request #18 from tiwillia/htpasswd
Implement HTPasswd identity provider setup
2 parents 93d086b + f65236a commit d53dffb

File tree

10 files changed

+1349
-52
lines changed

10 files changed

+1349
-52
lines changed

CLAUDE.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
This is a Model Context Protocol (MCP) server for ROSA HCP (Red Hat OpenShift Service on AWS using Hosted Control Planes) written in Go. It enables AI assistants to integrate with Red Hat Managed OpenShift services through 5 core tools: `whoami`, `get_clusters`, `get_cluster`, `create_rosa_hcp_cluster`, and `get_rosa_hcp_prerequisites_guide`.
7+
This is a Model Context Protocol (MCP) server for ROSA HCP (Red Hat OpenShift Service on AWS using Hosted Control Planes) written in Go. It enables AI assistants to integrate with Red Hat Managed OpenShift services through 6 core tools: `whoami`, `get_clusters`, `get_cluster`, `create_rosa_hcp_cluster`, `get_rosa_hcp_prerequisites_guide`, and `setup_htpasswd_identity_provider`.
88

99
## Build and Development Commands
1010

@@ -50,13 +50,18 @@ The codebase follows the Model Context Protocol (MCP) server pattern with clear
5050

5151
**MCP Layer (`pkg/mcp/`):**
5252
- `server.go` - Main MCP server implementation, handles transport (stdio/SSE) and authentication
53-
- `tools.go` - Implements all 4 ROSA HCP tools with parameter validation and OCM client interaction
53+
- `tools.go` - Implements all 6 ROSA HCP tools with parameter validation and OCM client interaction
5454
- `formatters.go` - Human-readable response formatters (not JSON) for AI assistant consumption
5555
- `profiles.go` - Tool profile system for selective tool exposure (currently default profile only)
5656

5757
**OCM Integration (`pkg/ocm/`):**
5858
- `client.go` - OCM SDK wrapper with authenticated connections and structured error handling
5959
- `auth.go` - Transport-agnostic token extraction (SSE headers vs stdio environment variables)
60+
- `htpasswd.go` - HTPasswd identity provider setup methods using ROSA CLI patterns
61+
62+
**ROSA CLI Integration (`pkg/htpasswd/`):**
63+
- `validation.go` - Username, password, and IDP name validation copied from ROSA CLI
64+
- `validation_test.go` - Comprehensive test suite for all validation functions
6065

6166
**Configuration (`pkg/config/`):**
6267
- `config.go` - TOML configuration file support with CLI flag overrides
@@ -87,14 +92,37 @@ Each tool follows this pattern:
8792

8893
All responses are human-readable formatted strings (not JSON) designed for AI assistant consumption. Each tool has a dedicated formatter in `formatters.go` that structures the output consistently.
8994

95+
### ROSA CLI Integration
96+
97+
The HTPasswd identity provider implementation (`setup_htpasswd_identity_provider` tool) integrates directly with ROSA CLI libraries and patterns:
98+
99+
**External Dependencies:**
100+
- `github.com/openshift-online/ocm-common` v0.0.25 - Password validation and HTPasswd hashing utilities
101+
102+
**ROSA CLI Function Integration (~70% code reuse):**
103+
- `UsernameValidator()` - Username format validation (no /, :, % characters)
104+
- `clusterAdminValidator()` - Reserved username check (prevents "cluster-admin")
105+
- `ValidateIdpName()` - IDP name validation with regex pattern matching
106+
- `ProcessUserInput()` - Simplified to handle only users array format
107+
108+
**Validation Flow:**
109+
1. IDP name validation using ROSA CLI regex patterns
110+
2. Username/password validation with ROSA CLI rules
111+
3. Password hashing with `ocm-common` utilities (always hash passwords)
112+
4. OCM API integration following ROSA CLI error handling patterns
113+
114+
**Input Format (Simplified):**
115+
- Users array format: `["user1:password1", "user2:password2"]` (required parameter)
116+
- Removed backward compatibility for single user and htpasswd file formats for better consistency
117+
90118
## Development Notes
91119

92120
- The project uses `github.com/mark3labs/mcp-go` v0.37.0+ as the MCP framework
93121
- OCM integration via `github.com/openshift-online/ocm-sdk-go`
94122
- Configuration supports CLI flags, environment variables, and TOML files
95123
- Uses glog for structured logging throughout the OCM SDK integration
96124
- OCM client supports configurable client ID (defaults to "cloud-services")
97-
- Only the `pkg/ocm` package currently has test coverage focusing on authentication logic
125+
- Test coverage includes `pkg/ocm` (authentication logic) and `pkg/htpasswd` (ROSA CLI validation functions)
98126
- The server binary is built to `rosa-mcp-server` in the project root
99127

100128
## Container and OpenShift Deployment

README.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ A Model Context Protocol (MCP) server for ROSA HCP (Red Hat OpenShift Service on
44

55
## Features
66

7-
- **5 Core Tools**: `whoami`, `get_clusters`, `get_cluster`, `create_rosa_hcp_cluster`, `get_rosa_hcp_prerequisites_guide`
7+
- **6 Core Tools**: `whoami`, `get_clusters`, `get_cluster`, `create_rosa_hcp_cluster`, `get_rosa_hcp_prerequisites_guide`, `setup_htpasswd_identity_provider`
8+
- **ROSA CLI Integration**: HTPasswd identity provider setup using proven ROSA CLI validation and patterns
89
- **Dual Transport Support**: stdio and Server-Sent Events (SSE)
910
- **OCM API Integration**: Direct integration with OpenShift Cluster Manager
1011
- **Multi-Region Support**: Configurable AWS regions (default: us-east-1)
@@ -197,6 +198,41 @@ Get the complete workflow prompt for ROSA HCP cluster installation prerequisites
197198
}
198199
```
199200

201+
### 6. setup_htpasswd_identity_provider
202+
Setup an HTPasswd identity provider for a ROSA HCP cluster with username/password authentication.
203+
```json
204+
{
205+
"name": "setup_htpasswd_identity_provider",
206+
"parameters": {
207+
"cluster_id": {
208+
"type": "string",
209+
"description": "Target cluster identifier",
210+
"required": true
211+
},
212+
"name": {
213+
"type": "string",
214+
"description": "Identity provider name",
215+
"default": "htpasswd"
216+
},
217+
"mapping_method": {
218+
"type": "string",
219+
"description": "User mapping method - options: add, claim, generate, lookup",
220+
"default": "claim"
221+
},
222+
"users": {
223+
"type": "array",
224+
"description": "List of username:password pairs [\"user1:password1\", \"user2:password2\"]",
225+
"required": true
226+
},
227+
"overwrite_existing": {
228+
"type": "boolean",
229+
"description": "Whether to overwrite if IDP with same name exists",
230+
"default": false
231+
}
232+
}
233+
}
234+
```
235+
200236
## ROSA HCP Prerequisites
201237

202238
Before creating clusters, ensure you have:
@@ -238,9 +274,11 @@ Before creating clusters, ensure you have:
238274
├── cmd/rosa-mcp-server/ # Main entry point
239275
├── pkg/
240276
│ ├── config/ # Configuration management
277+
│ ├── htpasswd/ # HTPasswd validation (ROSA CLI integration)
241278
│ ├── mcp/ # MCP server implementation
242279
│ ├── ocm/ # OCM API client wrapper
243280
│ └── version/ # Version information
281+
├── spec/ # Implementation specifications
244282
├── go.mod # Go module definition
245283
└── README.md # This file
246284
```

go.mod

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ go 1.24.4
44

55
require (
66
github.com/BurntSushi/toml v1.5.0
7-
github.com/golang/glog v1.0.0
7+
github.com/golang/glog v1.2.0
88
github.com/mark3labs/mcp-go v0.37.0
9+
github.com/openshift-online/ocm-common v0.0.25
910
github.com/openshift-online/ocm-sdk-go v0.1.473
1011
github.com/spf13/cobra v1.9.1
1112
github.com/spf13/pflag v1.0.6
@@ -18,36 +19,36 @@ require (
1819
github.com/beorn7/perks v1.0.1 // indirect
1920
github.com/buger/jsonparser v1.1.1 // indirect
2021
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
21-
github.com/cespare/xxhash/v2 v2.1.2 // indirect
22+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2223
github.com/davecgh/go-spew v1.1.1 // indirect
2324
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
24-
github.com/golang/protobuf v1.5.3 // indirect
25+
github.com/golang/protobuf v1.5.4 // indirect
2526
github.com/google/uuid v1.6.0 // indirect
2627
github.com/gorilla/css v1.0.0 // indirect
2728
github.com/inconshreveable/mousetrap v1.1.0 // indirect
2829
github.com/invopop/jsonschema v0.13.0 // indirect
2930
github.com/json-iterator/go v1.1.12 // indirect
3031
github.com/mailru/easyjson v0.7.7 // indirect
31-
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
32-
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
32+
github.com/matttproud/golang_protobuf_extensions v1.0.2 // indirect
33+
github.com/microcosm-cc/bluemonday v1.0.23 // indirect
3334
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
3435
github.com/modern-go/reflect2 v1.0.2 // indirect
3536
github.com/openshift-online/ocm-api-model/clientapi v0.0.426 // indirect
3637
github.com/openshift-online/ocm-api-model/model v0.0.426 // indirect
3738
github.com/pmezard/go-difflib v1.0.0 // indirect
38-
github.com/prometheus/client_golang v1.12.1 // indirect
39+
github.com/prometheus/client_golang v1.13.0 // indirect
3940
github.com/prometheus/client_model v0.2.0 // indirect
40-
github.com/prometheus/common v0.32.1 // indirect
41-
github.com/prometheus/procfs v0.7.3 // indirect
41+
github.com/prometheus/common v0.37.0 // indirect
42+
github.com/prometheus/procfs v0.8.0 // indirect
4243
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
4344
github.com/spf13/cast v1.7.1 // indirect
4445
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
4546
github.com/yosida95/uritemplate/v3 v3.0.2 // indirect
46-
golang.org/x/net v0.21.0 // indirect
47-
golang.org/x/oauth2 v0.15.0 // indirect
48-
golang.org/x/sys v0.17.0 // indirect
47+
golang.org/x/crypto v0.22.0 // indirect
48+
golang.org/x/net v0.24.0 // indirect
49+
golang.org/x/oauth2 v0.19.0 // indirect
50+
golang.org/x/sys v0.19.0 // indirect
4951
golang.org/x/text v0.14.0 // indirect
50-
google.golang.org/appengine v1.6.7 // indirect
51-
google.golang.org/protobuf v1.31.0 // indirect
52+
google.golang.org/protobuf v1.34.0 // indirect
5253
gopkg.in/yaml.v3 v3.0.1 // indirect
5354
)

0 commit comments

Comments
 (0)