-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Ensured that we have ClusterAccess CRD installed #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vertex451
wants to merge
10
commits into
main
Choose a base branch
from
feat/script
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8721eec
ensured that we have ClusterAccess CRD installed
vertex451 e78ee20
wait for CRD to be fully registered
vertex451 d13952d
addressed comments
vertex451 b5d4187
removed TOCTOU race
vertex451 483f358
fix(deps): update module sigs.k8s.io/controller-runtime to v0.22.2 (#67)
renovate[bot] 44bd887
fix(deps): update module golang.org/x/text to v0.30.0 (#70)
renovate[bot] 06d9d8c
Fix: relations nil pointer check (#68)
vertex451 dfa9b29
fix(deps): update golang.org/x/exp digest to d2f985d (#71)
renovate[bot] e332a37
improved docs
vertex451 093457e
Merge branch 'main' of github.com:platform-mesh/kubernetes-graphql-ga…
vertex451 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
# ClusterAccess Resource Setup | ||
|
||
To enable the gateway to access external Kubernetes clusters, you need to create ClusterAccess resources. This section provides both an automated script and manual step-by-step instructions. | ||
|
||
## Quick Setup (Recommended) | ||
|
||
For development purposes, use the provided script to automatically create ClusterAccess resources: | ||
|
||
**Example:** | ||
```bash | ||
./hack/create-clusteraccess.sh --target-kubeconfig ~/.kube/platform-mesh-config --management-kubeconfig ~/.kube/platform-mesh-config | ||
``` | ||
|
||
The script will: | ||
- Extract cluster name, server URL, and CA certificate from the target kubeconfig | ||
- Create a ServiceAccount with cluster-admin access in the target cluster | ||
- Generate a long-lived token for the ServiceAccount | ||
- Create the admin kubeconfig and CA secrets in the management cluster | ||
- Create the ClusterAccess resource with kubeconfig-based authentication | ||
- Output a copy-paste ready bearer token for direct API access | ||
|
||
## Manual Setup | ||
|
||
## Prerequisites | ||
|
||
- Access to the target cluster (the cluster you want to expose via GraphQL) | ||
- Access to the management cluster (the cluster where the gateway runs) | ||
- ClusterAccess CRDs installed in the management cluster | ||
- Target cluster kubeconfig file | ||
|
||
## Step 1: Create ServiceAccount with Admin Access in Target Cluster | ||
|
||
```bash | ||
# Switch to target cluster | ||
export KUBECONFIG=/path/to/target-cluster-kubeconfig | ||
|
||
# Create ServiceAccount with cluster-admin access | ||
cat <<EOF | kubectl apply -f - | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: kubernetes-graphql-gateway-admin | ||
namespace: default | ||
--- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: kubernetes-graphql-gateway-admin-cluster-admin | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: ClusterRole | ||
name: cluster-admin | ||
subjects: | ||
- kind: ServiceAccount | ||
name: kubernetes-graphql-gateway-admin | ||
namespace: default | ||
--- | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: kubernetes-graphql-gateway-admin-token | ||
namespace: default | ||
annotations: | ||
kubernetes.io/service-account.name: kubernetes-graphql-gateway-admin | ||
type: kubernetes.io/service-account-token | ||
EOF | ||
``` | ||
|
||
## Step 2: Extract CA Certificate from Target Cluster | ||
|
||
```bash | ||
# Extract CA certificate from kubeconfig | ||
kubectl config view --raw --minify -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 -d | ||
``` | ||
|
||
Copy the output (should start with `-----BEGIN CERTIFICATE-----` and end with `-----END CERTIFICATE-----`). | ||
|
||
## Step 3: Get Target Cluster Server URL | ||
|
||
```bash | ||
# Get the server URL | ||
kubectl config view --raw --minify -o jsonpath='{.clusters[0].cluster.server}' | ||
``` | ||
|
||
Copy the server URL (e.g., `https://127.0.0.1:58308`). | ||
|
||
## Step 4: Switch Back to Management Cluster | ||
|
||
```bash | ||
# Switch to the cluster where you'll create ClusterAccess | ||
export KUBECONFIG=/path/to/management-cluster-kubeconfig | ||
|
||
# Install ClusterAccess CRD if not already installed | ||
kubectl apply -f config/crd/ | ||
``` | ||
|
||
## Step 5: Create Secrets and ClusterAccess in Management Cluster | ||
|
||
Create a file called `my-cluster-access.yaml`: | ||
|
||
```yaml | ||
# Secret containing CA certificate for target-cluster | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: my-target-cluster-ca | ||
namespace: default | ||
type: Opaque | ||
stringData: | ||
ca.crt: | | ||
PASTE_CA_CERTIFICATE_FROM_STEP_2_HERE | ||
|
||
--- | ||
# Secret containing admin kubeconfig for target-cluster | ||
apiVersion: v1 | ||
kind: Secret | ||
metadata: | ||
name: my-target-cluster-admin-kubeconfig | ||
namespace: default | ||
type: Opaque | ||
data: | ||
kubeconfig: BASE64_ENCODED_TARGET_KUBECONFIG_HERE | ||
|
||
--- | ||
# ClusterAccess resource for target-cluster | ||
apiVersion: gateway.platform-mesh.io/v1alpha1 | ||
kind: ClusterAccess | ||
metadata: | ||
name: my-target-cluster | ||
spec: | ||
path: my-target-cluster # This becomes the filename in bin/definitions/ | ||
host: PASTE_SERVER_URL_FROM_STEP_3_HERE | ||
ca: | ||
secretRef: | ||
name: my-target-cluster-ca | ||
namespace: default | ||
key: ca.crt | ||
auth: | ||
kubeconfigSecretRef: | ||
name: my-target-cluster-admin-kubeconfig | ||
namespace: default | ||
``` | ||
|
||
To encode the kubeconfig: | ||
```bash | ||
cat /path/to/target-cluster-kubeconfig | base64 | ||
``` | ||
|
||
## Step 6: Apply the Configuration | ||
|
||
```bash | ||
kubectl apply -f my-cluster-access.yaml | ||
``` | ||
|
||
## Step 7: Verify Resources | ||
|
||
```bash | ||
# Check if ClusterAccess was created | ||
kubectl get clusteraccess | ||
|
||
# Check if secrets were created | ||
kubectl get secret my-target-cluster-admin-kubeconfig my-target-cluster-ca | ||
``` | ||
|
||
## Step 8: Test with Listener | ||
|
||
```bash | ||
export ENABLE_KCP=false | ||
export GATEWAY_SHOULD_IMPERSONATE=false | ||
export LOCAL_DEVELOPMENT=false | ||
export KUBECONFIG=/path/to/management-cluster-kubeconfig | ||
task listener | ||
``` | ||
|
||
## Key Points | ||
|
||
- **ServiceAccount**: Created in the target cluster with cluster-admin access for full permissions | ||
- **Kubeconfig**: Stored as a secret in the management cluster for authentication | ||
- **CA Certificate**: Essential for TLS verification - without it you'll get certificate errors | ||
- **Server URL**: Must match exactly from the target cluster's kubeconfig | ||
- **Path**: Becomes the schema filename (e.g., `my-target-cluster`) in `bin/definitions/` | ||
- **Secrets**: Keep them in the same namespace as the ClusterAccess resource | ||
|
||
The listener will detect the ClusterAccess resource and generate schema files with metadata that the gateway can use to access the target cluster. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
🧩 Analysis chain
Check GitHub issue link target.
Link points to openmfp/kubernetes-graphql-gateway#217. Confirm the org/repo is correct (this repo appears under platform-mesh).
🏁 Script executed:
Length of output: 523
Update issue link and wording
🤖 Prompt for AI Agents