gitea: constrain Veles tester feedback access

This commit is contained in:
jenkins 2026-06-20 15:07:12 -03:00
parent 566eafdfc7
commit 6cbfdd6091
5 changed files with 149 additions and 3 deletions

View File

@ -5,6 +5,14 @@ resources:
- namespace.yaml - namespace.yaml
- serviceaccount.yaml - serviceaccount.yaml
- pvc.yaml - pvc.yaml
- oneoffs/veles-feedback-acl-ensure-job.yaml
- deployment.yaml - deployment.yaml
- service.yaml - service.yaml
- ingress.yaml - ingress.yaml
configMapGenerator:
- name: veles-feedback-acl-ensure-script
namespace: gitea
files:
- scripts/veles_feedback_acl_ensure.sh
generatorOptions:
disableNameSuffixHash: true

View File

@ -0,0 +1,48 @@
# services/gitea/oneoffs/veles-feedback-acl-ensure-job.yaml
# One-off job for gitea/veles-feedback-acl-ensure-1.
# Purpose: keep Veles testers on the feedback repo without granting source access.
apiVersion: batch/v1
kind: Job
metadata:
name: veles-feedback-acl-ensure-1
namespace: gitea
spec:
suspend: false
backoffLimit: 0
template:
metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/agent-pre-populate-only: "true"
vault.hashicorp.com/role: "gitea"
vault.hashicorp.com/agent-inject-secret-gitea-db-secret__password: "kv/data/atlas/gitea/gitea-db-secret"
vault.hashicorp.com/agent-inject-template-gitea-db-secret__password: |
{{ with secret "kv/data/atlas/gitea/gitea-db-secret" }}
{{ .Data.data.password }}
{{ end }}
spec:
serviceAccountName: gitea-vault
restartPolicy: Never
volumes:
- name: veles-feedback-acl-ensure-script
configMap:
name: veles-feedback-acl-ensure-script
defaultMode: 0555
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/arch
operator: In
values: ["arm64"]
- key: node-role.kubernetes.io/worker
operator: Exists
containers:
- name: apply
image: postgres:15
command: ["/scripts/veles_feedback_acl_ensure.sh"]
volumeMounts:
- name: veles-feedback-acl-ensure-script
mountPath: /scripts
readOnly: true

View File

@ -0,0 +1,90 @@
#!/usr/bin/env sh
set -eu
db_host="${GITEA_DB_HOST:-postgres-service.postgres.svc.cluster.local}"
db_port="${GITEA_DB_PORT:-5432}"
db_name="${GITEA_DB_NAME:-gitea}"
db_user="${GITEA_DB_USER:-gitea}"
org_name="${VELES_GITEA_ORG:-veles-alpha}"
repo_name="${VELES_GITEA_FEEDBACK_REPO:-feedback}"
team_name="${VELES_GITEA_TESTER_TEAM:-testers}"
if [ ! -r /vault/secrets/gitea-db-secret__password ]; then
echo "Missing readable Vault secret file: /vault/secrets/gitea-db-secret__password" >&2
exit 1
fi
export PGPASSWORD
PGPASSWORD="$(tr -d '\r\n' </vault/secrets/gitea-db-secret__password)"
psql_base="psql -h ${db_host} -p ${db_port} -U ${db_user} -d ${db_name} -v ON_ERROR_STOP=1 -P pager=off"
${psql_base} \
-v org_name="${org_name}" \
-v repo_name="${repo_name}" \
-v team_name="${team_name}" <<'SQL'
begin;
create temporary table veles_acl_ids on commit drop as
select
org.id as org_id,
repo.id as repo_id,
team.id as team_id
from gitea."user" org
join gitea.repository repo
on repo.owner_id = org.id
join gitea.team team
on team.org_id = org.id
where org.lower_name = lower(:'org_name')
and org.type = 1
and repo.lower_name = lower(:'repo_name')
and team.lower_name = lower(:'team_name');
do $$
begin
if (select count(*) from veles_acl_ids) != 1 then
raise exception 'Expected one veles feedback ACL target, found %', (select count(*) from veles_acl_ids);
end if;
end $$;
update gitea.team team
set authorize = 1,
includes_all_repositories = true,
can_create_org_repo = false
from veles_acl_ids ids
where team.id = ids.team_id;
insert into gitea.team_repo (org_id, team_id, repo_id)
select ids.org_id, ids.team_id, ids.repo_id
from veles_acl_ids ids
where not exists (
select 1
from gitea.team_repo existing
where existing.team_id = ids.team_id
and existing.repo_id = ids.repo_id
);
delete from gitea.team_unit unit
using veles_acl_ids ids
where unit.team_id = ids.team_id
and unit.type in (1, 2, 3, 4, 5, 8, 9, 10);
insert into gitea.team_unit (org_id, team_id, type, access_mode)
select ids.org_id, ids.team_id, desired.type, desired.access_mode
from veles_acl_ids ids
cross join (
values
(1, 0),
(2, 2),
(3, 0),
(4, 0),
(5, 0),
(8, 0),
(9, 0),
(10, 0)
) as desired(type, access_mode);
commit;
SQL
echo "Veles feedback Gitea ACL ready"

View File

@ -1,12 +1,12 @@
# services/keycloak/oneoffs/veles-gitea-oidc-secret-ensure-job.yaml # services/keycloak/oneoffs/veles-gitea-oidc-secret-ensure-job.yaml
# One-off job for sso/veles-gitea-oidc-secret-ensure-4. # One-off job for sso/veles-gitea-oidc-secret-ensure-5.
# Purpose: create/update the Veles realm Gitea OIDC client and write the # Purpose: create/update the Veles realm Gitea OIDC client and write the
# matching Gitea auth-source secret to Vault. # matching Gitea auth-source secret to Vault.
# Keep suspended until the Vault policy change has reconciled, then unsuspend once. # Keep suspended until the Vault policy change has reconciled, then unsuspend once.
apiVersion: batch/v1 apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: veles-gitea-oidc-secret-ensure-4 name: veles-gitea-oidc-secret-ensure-5
namespace: sso namespace: sso
spec: spec:
suspend: true suspend: true

View File

@ -10,7 +10,7 @@ PUBLIC_BASE_URL="${GITEA_PUBLIC_BASE_URL:-https://scm.bstein.dev}"
AUTH_SOURCE_NAME="${GITEA_AUTH_SOURCE_NAME:-veles}" AUTH_SOURCE_NAME="${GITEA_AUTH_SOURCE_NAME:-veles}"
TESTER_GROUP="${VELES_GITEA_TESTER_GROUP:-veles-tester}" TESTER_GROUP="${VELES_GITEA_TESTER_GROUP:-veles-tester}"
VAULT_SECRET_PATH="${VAULT_SECRET_PATH:-gitea/gitea-veles-oidc}" VAULT_SECRET_PATH="${VAULT_SECRET_PATH:-gitea/gitea-veles-oidc}"
GROUP_TEAM_MAP="${GITEA_GROUP_TEAM_MAP:-}" GROUP_TEAM_MAP="${GITEA_GROUP_TEAM_MAP:-{\"veles-tester\":{\"veles-alpha\":[\"testers\"]}}}"
ACCESS_TOKEN="" ACCESS_TOKEN=""
for attempt in 1 2 3 4 5 6 7 8 9 10; do for attempt in 1 2 3 4 5 6 7 8 9 10; do