SIMULATIONCreate a network policy named allow-np, that allows pod in the namespace staging to connect to port 80 of other pods in the same namespace.Ensure that Network Policy:-1. Does not allow access to pod not listening on port 80.2. Does not allow access from Pods, not in namespace staging.
Answer(s): A
apiVersion: networking.k8s.io/v1kind: NetworkPolicy metadata:name: network-policy spec:podSelector: {} #selects all the pods in the namespace deployed policyTypes:- Ingress ingress:- ports: #in input traffic allowed only through 80 port only- protocol: TCPport: 80
SIMULATIONCreate a Pod name Nginx-pod inside the namespace testing, Create a service for the Nginx-pod named nginx-svc, using the ingress of your choice, run the ingress on tls, secure port.
$ kubectl get ing -n <namespace-of-ingress-resource>NAME HOSTS ADDRESS PORTS AGEcafe-ingress cafe.com 10.0.2.15 80 25s$ kubectl describe ing <ingress-resource-name> -n <namespace-of-ingress-resource>Name: cafe-ingressNamespace: defaultAddress: 10.0.2.15Default backend: default-http-backend:80 (172.17.0.5:8080)Rules:Host Path Backends----------------cafe.com/tea tea-svc:80 (<none>)/coffee coffee-svc:80 (<none>)Annotations:kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"networking.k8s.io/v1","kind":"Ingress","metadata":{"annotations":{},"name":"cafe-ingress","namespace":"default","selfLink":"/apis/networking/v1/namespaces/default/ingresses/cafe -ingress"},"spec":{"rules":[{"host":"cafe.com","http":{"paths":[{"backend":{"serviceName":"tea-svc","servicePort":80},"path":"/tea"},{"backend":{"serviceName":"coffee-svc","servicePort":80},"path":"/coffee"}]}}]},"status":{"loadBalancer":{"ingress":[{"ip":"169.48.142.11 0"}]}}}Events:Type Reason Age From Message-------------------------Normal CREATE 1m ingress-nginx-controller Ingress default/cafe-ingressNormal UPDATE 58s ingress-nginx-controller Ingress default/cafe-ingress$ kubectl get pods -n <namespace-of-ingress-controller>NAME READY STATUS RESTARTS AGEingress-nginx-controller-67956bf89d-fv58j 1/1 Running 0 1m$ kubectl logs -n <namespace> ingress-nginx-controller-67956bf89d-fv58j-------------------------------------------------------------------------------NGINX Ingress controllerRelease: 0.14.0Build: git-734361dRepository: https://github.com/kubernetes/ingress-nginx-------------------------------------------------------------------------------....
SIMULATIONSecrets stored in the etcd is not secure at rest, you can use the etcdctl command utility to find the secret value for e.g:-ETCDCTL_API=3 etcdctl get /registry/secrets/default/cks-secret --cacert="ca.crt" --cert="server.crt" --key="server.key"OutputUsing the Encryption Configuration, Create the manifest, which secures the resource secrets using the provider AES-CBC and identity, to encrypt the secret-data at rest and ensure all secrets are encrypted with the new configuration.
ETCD secret encryption can be verified with the help of etcdctl command line utility.ETCD secrets are stored at the path /registry/secrets/$namespace/$secret on the master node.The below command can be used to verify if the particular ETCD secret is encrypted or not.# ETCDCTL_API=3 etcdctl get /registry/secrets/default/secret1 [...] | hexdump -C
SIMULATIONService is running on port 389 inside the system, find the process-id of the process, and stores the names of all the open-files inside the /candidate/KH77539/files.txt, and also delete the binary.
root# netstat -ltnupActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 127.0.0.1:17600 0.0.0.0:* LISTEN 1293/dropbox tcp 0 0 127.0.0.1:17603 0.0.0.0:* LISTEN 1293/dropbox tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 575/sshd tcp 0 0 127.0.0.1:9393 0.0.0.0:* LISTEN 900/perl tcp 0 0 :::80 :::* LISTEN 9583/docker-proxy tcp 0 0 :::443 :::* LISTEN 9571/docker-proxy udp 0 0 0.0.0.0:68 0.0.0.0:* 8822/dhcpcd...root# netstat -ltnup | grep ':22'tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 575/sshdThe ss command is the replacement of the netstat command.Now let’s see how to use the ss command to see which process is listening on port 22:root# ss -ltnup 'sport = :22'Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:("sshd",pid=575,fd=3))
SIMULATIONUse the kubesec docker images to scan the given YAML manifest, edit and apply the advised changes, and passed with a score of 4 points.kubesec-test.yaml apiVersion: v1kind: Pod metadata:name: kubesec-demo spec:containers:- name: kubesec-demo image: gcr.io/google-samples/node-hello:1.0securityContext:readOnlyRootFilesystem: trueHint: docker run -i kubesec/kubesec:512c5e0 scan /dev/stdin < kubesec-test.yaml
kubesec scan k8s-deployment.yaml cat <<EOF > kubesec-test.yaml apiVersion: v1kind: Pod metadata:name: kubesec-demo spec:containers:- name: kubesec-demo image: gcr.io/google-samples/node-hello:1.0securityContext:readOnlyRootFilesystem: trueEOFkubesec scan kubesec-test.yaml docker run -i kubesec/kubesec:512c5e0 scan /dev/stdin < kubesec-test.yaml kubesec http 8080 &[1] 12345{"severity":"info","timestamp":"2019-05-12T11:58:34.662+0100","caller":"server/server.go:69","message":"Starting HTTP server on port 8080"}curl -sSX POST --data-binary @test/asset/score-0-cap-sys-admin.yml http://localhost:8080/scan[{"object": "Pod/security-context-demo.default","valid": true,"message": "Failed with a score of -30 points","score": -30,"scoring": {"critical": [{"selector": "containers[] .securityContext .capabilities .add == SYS_ADMIN","reason": "CAP_SYS_ADMIN is the most privileged capability and should always be avoided"},{"selector": "containers[] .securityContext .runAsNonRoot == true","reason": "Force the running image to run as a non-root user to ensure least privilege"},// ...
Post your Comments and Discuss Linux Foundation CKS exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the CKS content, but please register or login to continue.