add woodpecker pipeline to reconcile flux
Some checks failed
ci/woodpecker/push/flux-reconcile-source Pipeline failed
Some checks failed
ci/woodpecker/push/flux-reconcile-source Pipeline failed
This commit is contained in:
49
.woodpecker/flux-reconcile-source.yaml
Normal file
49
.woodpecker/flux-reconcile-source.yaml
Normal file
@@ -0,0 +1,49 @@
|
||||
when:
|
||||
- event: push
|
||||
branch: fresh-start
|
||||
|
||||
skip_clone: true
|
||||
|
||||
steps:
|
||||
- name: Get kubernetes access from OpenBao
|
||||
image: quay.io/openbao/openbao:2.5.2
|
||||
environment:
|
||||
VAULT_ADDR: https://openbao.lumpiasty.xyz:8200
|
||||
ROLE_ID:
|
||||
from_secret: flux_reconcile_role_id
|
||||
SECRET_ID:
|
||||
from_secret: flux_reconcile_secret_id
|
||||
commands:
|
||||
- bao write -field token auth/approle/login
|
||||
role_id=$ROLE_ID
|
||||
secret_id=$SECRET_ID > /woodpecker/.vault_id
|
||||
- export VAULT_TOKEN=$(cat /woodpecker/.vault_id)
|
||||
- bao write -format json -f /kubernetes/creds/flux-reconcile > /woodpecker/kube_credentials
|
||||
- name: Construct Kubeconfig
|
||||
image: alpine/k8s:1.32.13
|
||||
environment:
|
||||
KUBECONFIG: /woodpecker/kubeconfig
|
||||
commands:
|
||||
- kubectl config set-cluster cluster
|
||||
--server=https://$KUBERNETES_SERVICE_HOST
|
||||
--certificate-authority=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
|
||||
- kubectl config set-credentials cluster
|
||||
--token=$(jq -r .data.service_account_token /woodpecker/kube_credentials)
|
||||
- kubectl config set-context cluster
|
||||
--cluster cluster
|
||||
--user cluster
|
||||
--namespace flux-system
|
||||
- kubectl config use-context cluster
|
||||
- name: Reconcile git source
|
||||
image: ghcr.io/fluxcd/flux-cli:v2.8.3
|
||||
environment:
|
||||
KUBECONFIG: /woodpecker/kubeconfig
|
||||
commands:
|
||||
- flux reconcile source git flux-system
|
||||
- name: Invalidate OpenBao token
|
||||
image: quay.io/openbao/openbao:2.5.2
|
||||
environment:
|
||||
VAULT_ADDR: https://openbao.lumpiasty.xyz:8200
|
||||
commands:
|
||||
- export VAULT_TOKEN=$(cat /woodpecker/.vault_id)
|
||||
- bao write -f auth/token/revoke-self
|
||||
@@ -73,6 +73,28 @@ def synchronize_approle_auth(client: hvac.Client):
|
||||
print('Enabling AppRole auth method')
|
||||
client.sys.enable_auth_method('approle', 'AppRole authorization for CI')
|
||||
|
||||
roles_dir = pathlib.Path(__file__).parent.joinpath('../vault/approles/')
|
||||
roles: dict[str, Any] = {}
|
||||
|
||||
for filename in roles_dir.iterdir():
|
||||
with filename.open('r') as f:
|
||||
role = yaml.safe_load(f.read())
|
||||
assert type(role) is dict
|
||||
roles[filename.stem] = role
|
||||
|
||||
roles_on_vault: list[str] = []
|
||||
roles_response = client.list("auth/approle/roles")
|
||||
if roles_response is not None:
|
||||
roles_on_vault = roles_response['data']['keys']
|
||||
|
||||
for role in roles_on_vault:
|
||||
if role not in roles:
|
||||
print(f'Deleting role: {role}')
|
||||
client.delete(f'auth/approle/role/{role}')
|
||||
|
||||
for role_name, role_content in roles.items():
|
||||
print(f'Updating role: {role_name}')
|
||||
client.write_data(f'auth/approle/role/{role_name}', data=role_content)
|
||||
|
||||
def synchronize_kubernetes_secretengine(client: hvac.Client):
|
||||
# Ensure kubernetes secret engine is enabled
|
||||
|
||||
4
vault/approles/ci-flux-reconcile.yaml
Normal file
4
vault/approles/ci-flux-reconcile.yaml
Normal file
@@ -0,0 +1,4 @@
|
||||
token_ttl: 20m
|
||||
token_max_ttl: 20m
|
||||
policies:
|
||||
- flux-reconcile
|
||||
@@ -3,4 +3,4 @@ generated_role_rules:
|
||||
rules:
|
||||
- apiGroups: ["kustomize.toolkit.fluxcd.io"]
|
||||
resources: ["gitrepositories"]
|
||||
verbs: ["update", "watch"]
|
||||
verbs: ["get", "update", "watch"]
|
||||
|
||||
3
vault/policy/flux-reconcile.hcl
Normal file
3
vault/policy/flux-reconcile.hcl
Normal file
@@ -0,0 +1,3 @@
|
||||
path "kubernetes/creds/flux-reconcile" {
|
||||
capabilities = ["update"]
|
||||
}
|
||||
Reference in New Issue
Block a user