-
Notifications
You must be signed in to change notification settings - Fork 41
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
Update k8s deployments and add cluster-wide configs #157
Merged
MartinPetkov
merged 7 commits into
GoogleCloudPlatform:terraform
from
MartinPetkov:add-kubernetes-yamls
Apr 17, 2020
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aff23ec
Update k8s deployments and add cluster-wide configs
MartinPetkov 6c38d0f
Remove the response-server-ws-gcloud-key user-registration-server-ws-…
MartinPetkov 607de0b
Revert "Remove the response-server-ws-gcloud-key user-registration-se…
MartinPetkov 4927cff
Make apps use separate SAs, gcloud keys, and DB creds
MartinPetkov e7dc1c0
Merge branch 'terraform' into add-kubernetes-yamls
MartinPetkov 2ba0451
Include changes to ingress.yaml from early-access
MartinPetkov 8a20f3f
Add usage and args to the push_images.sh script
MartinPetkov 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
**/.terraform | ||
*.tfstate | ||
*.tfstate.* | ||
sql_credentials.json | ||
key.json |
This file contains 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 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 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 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 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 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 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,7 @@ | ||
apiVersion: networking.gke.io/v1beta1 | ||
kind: ManagedCertificate | ||
metadata: | ||
name: heroes-hat-cert | ||
spec: | ||
domains: | ||
- heroes-hat.rocketturtle.net | ||
MartinPetkov marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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,15 @@ | ||
apiVersion: networking.k8s.io/v1beta1 | ||
kind: Ingress | ||
metadata: | ||
name: heroes-hat-dev | ||
annotations: | ||
kubernetes.io/ingress.global-static-ip-name: heroes-hat | ||
networking.gke.io/managed-certificates: heroes-hat-cert | ||
spec: | ||
rules: | ||
- http: | ||
MartinPetkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
paths: | ||
- path: /AuthServer/* | ||
backend: | ||
serviceName: auth-server-np | ||
servicePort: 50000 |
This file contains 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,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Short helper script to run repetitive commands for Kubernetes deployments. | ||
# Args: | ||
# kubeapply.sh <project> <region> <cluster> | ||
# | ||
# It does the following: | ||
# * Activate sthe cluster for kubectl via `gcloud container clusters get-credentials`. | ||
# * Applies the pod security policies. | ||
# * Applies the heroes-hat cert configuration. | ||
# * Applies all services from children of the parent folder. | ||
# * Applies the ingress configuration | ||
# | ||
# The services and deployments should be applied separately. | ||
# | ||
# Requires existence of files ./pod_security_policy{,-istio}.yaml. | ||
# Currently hardcoded to use projects "heroes-hat-dev-{apps,data}". | ||
# | ||
# Run like: | ||
# $ ./kubernetes/kubeapply.sh heroes-hat-cluster | ||
|
||
if [ "$#" -ne 1 ]; then | ||
echo 'Please provide exactly 1 argument in the order of <cluster>' | ||
exit 1 | ||
fi | ||
|
||
cluster="${1}" | ||
shift 1 | ||
|
||
set -e | ||
|
||
serviceaccount="$(gcloud container clusters describe "${cluster}" --region="us-east1" --project="heroes-hat-dev-apps" --format='value(nodeConfig.serviceAccount)')" | ||
|
||
echo "=== Switching kubectl to cluster ${cluster} ===" | ||
read -p "Press enter to continue" | ||
gcloud container clusters get-credentials "${cluster}" --region="us-east1" --project="heroes-hat-dev-apps" | ||
|
||
for policy in $(find . -name "pod_security_policy*.yaml"); do | ||
echo "=== Applying ${policy} ===" | ||
read -p "Press enter to continue" | ||
kubectl apply -f ${policy} | ||
done | ||
|
||
echo '=== Applying heroes-hat-cert.yaml ===' | ||
read -p "Press enter to continue" | ||
kubectl apply -f ./heroes-hat-cert.yaml | ||
|
||
for service in $(find .. -name "service.yaml"); do | ||
echo "=== Applying service ${service} ===" | ||
read -p "Press enter to continue" | ||
kubectl apply -f ${service} | ||
done | ||
|
||
echo '=== Applying ingress.yaml ===' | ||
read -p "Press enter to continue" | ||
kubectl apply -f ./ingress.yaml |
This file contains 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,60 @@ | ||
# Taken from https://github.com/istio/istio/issues/6806#issuecomment-406230278 | ||
|
||
# Istio containers need to run as root with a pretty loose policy. | ||
# See: https://github.com/istio/istio/issues/6806 | ||
|
||
apiVersion: policy/v1beta1 | ||
kind: PodSecurityPolicy | ||
metadata: | ||
name: pod-security-policy-istio | ||
annotations: | ||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default' | ||
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default' | ||
spec: | ||
privileged: false | ||
allowedCapabilities: | ||
- '*' | ||
volumes: | ||
- '*' | ||
# Required to prevent escalations to root. | ||
allowPrivilegeEscalation: true | ||
runAsUser: | ||
rule: 'RunAsAny' | ||
seLinux: | ||
rule: 'RunAsAny' | ||
supplementalGroups: | ||
rule: 'RunAsAny' | ||
fsGroup: | ||
rule: 'RunAsAny' | ||
readOnlyRootFilesystem: false | ||
--- | ||
# ClusterRole for reading the policy. | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: pod-security-policy-clusterrole-istio | ||
rules: | ||
- apiGroups: ['policy'] | ||
resources: ['podsecuritypolicies'] | ||
verbs: ['use'] | ||
resourceNames: | ||
- pod-security-policy-istio | ||
--- | ||
# Binding for reading the policy via the role. | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: pod-security-policy-rolebinding-istio | ||
namespace: istio-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: pod-security-policy-clusterrole-istio | ||
apiGroup: rbac.authorization.k8s.io | ||
subjects: | ||
# Authorize all service accounts in the Istio namespace. | ||
- kind: Group | ||
apiGroup: rbac.authorization.k8s.io | ||
name: system:serviceaccounts | ||
- kind: Group | ||
apiGroup: rbac.authorization.k8s.io | ||
name: system:authenticated |
This file contains 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,84 @@ | ||
# Taken from https://kubernetes.io/docs/concepts/policy/pod-security-policy/#example-policies | ||
|
||
# This is an example of a restrictive policy that requires users to run as an | ||
# unprivileged user, blocks possible escalations to root, and requires use of | ||
# several security mechanisms. | ||
apiVersion: policy/v1beta1 | ||
kind: PodSecurityPolicy | ||
metadata: | ||
name: pod-security-policy | ||
annotations: | ||
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default' | ||
apparmor.security.beta.kubernetes.io/allowedProfileNames: 'runtime/default' | ||
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default' | ||
apparmor.security.beta.kubernetes.io/defaultProfileName: 'runtime/default' | ||
spec: | ||
privileged: false | ||
# Required to prevent escalations to root. | ||
allowPrivilegeEscalation: false | ||
# This is redundant with non-root + disallow privilege escalation, | ||
# but we can provide it for defense in depth. | ||
requiredDropCapabilities: | ||
- ALL | ||
# Allow core volume types. | ||
volumes: | ||
- 'configMap' | ||
- 'emptyDir' | ||
- 'projected' | ||
- 'secret' | ||
- 'downwardAPI' | ||
# Assume that persistentVolumes set up by the cluster admin are safe to use. | ||
- 'persistentVolumeClaim' | ||
hostNetwork: false | ||
hostIPC: false | ||
hostPID: false | ||
runAsUser: | ||
# Require the container to run without root privileges. | ||
# The FDA MyStudies containers run as root. | ||
#rule: 'MustRunAsNonRoot' | ||
rule: 'RunAsAny' | ||
seLinux: | ||
# This policy assumes the nodes are using AppArmor rather than SELinux. | ||
rule: 'RunAsAny' | ||
supplementalGroups: | ||
rule: 'MustRunAs' | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
fsGroup: | ||
rule: 'MustRunAs' | ||
ranges: | ||
# Forbid adding the root group. | ||
- min: 1 | ||
max: 65535 | ||
readOnlyRootFilesystem: false | ||
--- | ||
# Role for reading the policy. | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: ClusterRole | ||
metadata: | ||
name: pod-security-policy-clusterrole | ||
namespace: default | ||
rules: | ||
- apiGroups: ['policy'] | ||
resources: ['podsecuritypolicies'] | ||
verbs: ['use'] | ||
resourceNames: | ||
- pod-security-policy | ||
--- | ||
# Binding for reading the policy via the role. | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: pod-security-policy-rolebinding | ||
namespace: default | ||
roleRef: | ||
kind: ClusterRole | ||
name: pod-security-policy-clusterrole | ||
apiGroup: rbac.authorization.k8s.io | ||
subjects: | ||
# Authorize all service accounts in the namespace. | ||
- kind: Group | ||
apiGroup: rbac.authorization.k8s.io | ||
name: system:serviceaccounts |
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.
this seems to be different from the previous instance, both database name and region are changed. Is that intentional?
nit: would be great if we could extract all these values out of the yaml files and make the deployment configurable.
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.
They are different, these are for the project we've been deploying to, not the main heroes-hat-dev. These would presumably have to change before going to UNC, to point to their particular project(s).
I'll look into making this configurable, though I'm not very familiar with customizable Kubernetes configs. Maybe we need something like kustomize, but I haven't explored it yet.
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.
So I did a small literature review, and none of the options seem great. In particular, this is a great overview.
-instances=heroes-hat-dev-data:us-central1:my-studies-1=tcp:3306
flags, in all the deployment.yaml files.All that said, I think it's simplest to just replace the values (either manually or via sed) before attempting to deploy in the final GCP project.
Let me know if you'd still like to discuss, or if I can resolve.