Skip to content
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

feat!: add netpols and monitoring #81

Merged
merged 8 commits into from
May 16, 2024
2 changes: 1 addition & 1 deletion chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.runnerNamespace }}
name: {{ .Values.sandboxNamespace }}
rules:
- apiGroups: [""]
resources: ["configmaps", "pods", "pods/attach", "secrets", "services"]
Expand Down
4 changes: 1 addition & 3 deletions chart/templates/namespace.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.runnerNamespace }}
labels:
istio-injection: enabled
name: {{ .Values.sandboxNamespace }}
8 changes: 4 additions & 4 deletions chart/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.runnerNamespace }}
namespace: {{ .Values.runnerNamespace }}
name: {{ .Values.sandboxNamespace }}
namespace: {{ .Values.sandboxNamespace }}
subjects:
- kind: ServiceAccount
name: default
name: {{ .Values.serviceAccountName }}
namespace: gitlab-runner
roleRef:
apiGroup: ""
kind: ClusterRole
name: {{ .Values.runnerNamespace }}
name: {{ .Values.sandboxNamespace }}
40 changes: 40 additions & 0 deletions chart/templates/uds-package-sandbox.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: uds.dev/v1alpha1
kind: Package
metadata:
name: gitlab-runner-sandbox
namespace: {{ .Values.sandboxNamespace }}
spec:
network:
allow:
- direction: Egress
selector:
uds/network-access-gitlab: "true"
remoteNamespace: gitlab
remoteSelector:
app: webservice
port: 8181

- direction: Ingress
selector:
uds/network-access-gitlab: "true"
remoteNamespace: gitlab-runner
remoteSelector:
app: gitlab-runner

- direction: Egress
Racer159 marked this conversation as resolved.
Show resolved Hide resolved
remoteGenerated: KubeAPI

zachariahmiller marked this conversation as resolved.
Show resolved Hide resolved
{{- range .Values.customSandbox }}
- direction: {{ .direction }}
selector:
{{ .selector | toYaml | nindent 10 }}
{{- if not .remoteGenerated }}
remoteNamespace: {{ .remoteNamespace }}
remoteSelector:
{{ .remoteSelector | toYaml | nindent 10 }}
port: {{ .port }}
{{- else }}
remoteGenerated: {{ .remoteGenerated }}
{{- end }}
description: {{ .description }}
{{- end }}
41 changes: 30 additions & 11 deletions chart/templates/uds-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,47 @@ metadata:
name: gitlab-runner
namespace: {{ .Release.Namespace }}
spec:
monitor:
- selector:
app: gitlab-runner
targetPort: 9252
portName: metrics
description: Metrics

network:
allow:
- direction: Egress
podLabels:
selector:
app: gitlab-runner
remoteNamespace: gitlab
remotePodLabels:
remoteSelector:
app: webservice
port: 8181

- direction: Ingress
remoteGenerated: IntraNamespace

- direction: Egress
remoteGenerated: IntraNamespace

- direction: Egress
podLabels:
app: gitlab-runner
remoteNamespace: {{ .Values.runnerNamespace }}
remoteGenerated: KubeAPI

- direction: Egress
podLabels:
selector:
app: gitlab-runner
remoteGenerated: KubeAPI
remoteNamespace: {{ .Values.sandboxNamespace }}
remoteSelector:
uds/network-access-gitlab: "true"

# Custom rules for unanticipated scenarios
{{- range .Values.custom }}
- direction: {{ .direction }}
selector:
{{ .selector | toYaml | nindent 10 }}
{{- if not .remoteGenerated }}
remoteNamespace: {{ .remoteNamespace }}
remoteSelector:
{{ .remoteSelector | toYaml | nindent 10 }}
port: {{ .port }}
{{- else }}
remoteGenerated: {{ .remoteGenerated }}
{{- end }}
description: {{ .description }}
{{- end }}
11 changes: 10 additions & 1 deletion chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
runnerNamespace: "gitlab-runner-sandbox"
sandboxNamespace: "gitlab-runner-sandbox"
serviceAccountName: "gitlab-runner"
custom: []
# - direction: Egress
# remoteGenerated: Anywhere
# description: "Egress from to external GitLab"
customSandbox: []
# - direction: Egress
# remoteGenerated: Anywhere
# description: "Egress from to external GitLab"
10 changes: 5 additions & 5 deletions tasks.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
includes:
- dependencies: ./tasks/dependencies.yaml
- test: ./tasks/test.yaml
- create: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/create.yaml
- lint: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/lint.yaml
- pull: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/pull.yaml
- deploy: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/deploy.yaml
- setup: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/setup.yaml
- create: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/create.yaml
- lint: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/lint.yaml
- pull: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/pull.yaml
- deploy: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/deploy.yaml
- setup: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/setup.yaml

tasks:
- name: default
Expand Down
4 changes: 2 additions & 2 deletions tasks/publish.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
includes:
- create: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/create.yaml
- publish: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.0/tasks/publish.yaml
- create: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/create.yaml
- publish: https://raw.githubusercontent.com/defenseunicorns/uds-common/v0.4.2/tasks/publish.yaml

tasks:
- name: package
Expand Down
19 changes: 18 additions & 1 deletion values/common-values.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
unregisterRunners: true


# Create a non-default service account with the name gitlab-runner with minimal permissions
rbac:
create: false
create: true
generatedServiceAccountName: gitlab-runner
rules:
- resources: [""]
- apiGroups: [""]
resources: [""]
verbs: ["*"]
- apiGroups: [""]
resources: [""]
verbs: [""]
zachariahmiller marked this conversation as resolved.
Show resolved Hide resolved

runners:
secret: gitlab-gitlab-runner-secret
Expand All @@ -25,6 +36,7 @@ runners:
"pipeline_id" = "${CI_PIPELINE_ID}"
"uds/user" = "${UDS_RUN_AS_USER}"
"uds/group" = "${UDS_RUN_AS_GROUP}"
"uds/network-access-gitlab" = "true"
[runners.kubernetes.helper_container_security_context]
run_as_non_root = true
run_as_user = 1001
Expand All @@ -43,6 +55,11 @@ securityContext:
capabilities:
drop: ["ALL"]

service:
enabled: true
metrics:
enabled: true


resources:
limits:
Expand Down
3 changes: 2 additions & 1 deletion values/config-values.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
runnerNamespace: "###ZARF_VAR_JOB_RUNNER_NAMESPACE###"
sandboxNamespace: "###ZARF_VAR_JOB_RUNNER_NAMESPACE###"
serviceAccountName: "gitlab-runner"