Kubernetes 1.25����̃X�^���_�[�h�uPod Security Admission�v��Pod�^�R���e�i�̃Z�L�����e�B���������悤�FCloud Native�`�[�g�V�[�g�i20�j

Kubernetes��N���E�h�l�C�e�B�u�����֗��ɗ��p����Z�p��c�[���̊T�v�A�g�������Ïk���ďЉ��A�ځB2022�N8��23����Kubernetes v1.25�������[�X����܂����B���̃o�[�W�����ł́uPod Security Policy�v���폜����A�uPod Security Admission�v��GA�ɂȂ�APod�Z�L�����e�B�̃f�t�@�N�g�X�^���_�[�g���o�g���^�b�`����܂����B����́A����Pod Security Admission�ɂ‚��ďډ����܂��iKubernetes v1.31�ɍ����悤�ɍX�V�j�B

» 2024�N12��17�� 05��00�� ���J
[�]���h��, ���{���j, ����E�k�C�������NTT�f�[�^]

���̋L���͉������ł��B����o�^�i�����j����ƑS�Ă������������܂��B

�@Kubernetes�͍���R���e�i���s��Ղ̃f�t�@�N�g�X�^���_�[�h�ł����A�����Ƀf�v���C����R���e�i�iPod�j�̐ݒ�ɂ‚��āA�ǂ̒��x�ӎ��ł��Ă���ł��傤���BKubernetes��Pod���f�v���C����ۂɂ́A�}�j�t�F�X�g�ŃR���e�i�ɑ΂��邳�܂��܂Ȑݒ肪�ł��܂��B�������A���̐ݒ莟��ł́A�f�v���C����Pod�A�Ђ��Ă�Kubernetes�N���X�^�S�̂ɒv���I�ȐƎ�i�������Ⴍ�j���������炷���Ƃɂ‚Ȃ���܂��B

�@Kubernetes�ł́A���̂悤��Pod�ɑ΂���Ǝ�Ȑݒ�𖢑R�ɖh���@�\�Ƃ��āA����܂ł́uPod Security Policy�v�����łƂ��Ē񋟂���Ă��܂������A�{�@�\�͐��������[�X�iGA�j�œ��̖ڂ����邱�ƂȂ�Kubernetes v1.25�ō폜����܂����B����ɑ���@�\�Ƃ���Kubernetes v1.25�ȍ~�ł́A�uPod Security Admission�v��GA�ƂȂ�A�����ɗ��p�ł���悤�ɂȂ�܂����B

�@Kubernetes��N���E�h�l�C�e�B�u�����֗��ɗ��p����Z�p��c�[���̊T�v�A�g�������Ïk���ďЉ��{�A�ځuCloud Native�`�[�g�V�[�g�v�B����́A�Ǝ�Ȑݒ�ɂ��Z�L�����e�B���X�N�𓥂܂��APod Security Admission��p���Ăǂ̂悤�ɃZ�L�����e�B���X�N��������邩�ɂ‚��ĉ�����܂��B

�R���e�i�̃��X�N�Ƃ́H

�@�Ǝ�ȃR���e�i�ݒ���܂�Pod��Kubernetes�Ƀf�v���C����ƁA�ȉ��̂悤�ȃ��X�N�ɂ‚Ȃ���ꍇ������܂��B

�O���̍U���҂Ɋ�Ղ��������郊�X�N

�@�Ǝ�ȃR���e�i�̐ݒ���܂񂾏�Ԃ�Web�T�[�oPod���f�v���C���A�O���Ɍ��J���Ă���P�[�X��z�肵�܂��B

�@����A�O���̍U���҂����炩�̎�i�ɂ����Web�T�[�oPod�ɐN���ł����ꍇ�A�U���҂̓R���e�i�̐Ǝ㐫�����p����Web�T�[�oPod�݂̂Ȃ炸�A����Pod���f�v���C����Ă���z�X�g��A���̃z�X�g��œ��삵�Ă��鑼��Pod�ȂǁA�U���͈̔͂�����Pod�����łȂ���ՑS�̂Ɋg��ł��邱�ƂɂȂ�܂��B

�A�v���J���҂��^����ꂽ�������z���ăN���X�^�𑀍�ł��郊�X�N

�@Kubernetes�N���X�^���R���e�i��ՂƂ��ăA�v���J���҂ɒ񋟂��Ă���P�[�X��z�肵�܂��B�A�v���J���҂ɂ�Kubernetes��Pod���f�v���C����Ƃ�������{�I�ȑ���͋��‚������ł����AWorker Node�Ȃǂ̃N���X�^�\���v�f�ɂ̓A�N�Z�X������������܂���B

�@�Ƃ��낪�A���ӂ̂���A�v���J���҂��Ǝ�ȃR���e�i�ݒ���܂�Pod��Kubernetes�Ƀf�v���C�����ꍇ�A���ӂ̂���J���҂͎��g�̃f�v���C����Pod���o�R���Ė{�������̗^�����Ă��Ȃ�Worker Node�ɕs���ɃA�N�Z�X���A�U���ł��Ă��܂��P�[�X������܂��B

�Ǝ�ȃR���e�i�ݒ�ɂ�郊�X�N�̋�̗�

�@�Ǝ�ȃR���e�i�̐ݒ�ɔ������X�N�̗��2�_�����܂������A�������������Ă���̓I�ɂ҂�Ƃ��Ȃ����������Ǝv���܂��B�����ŋ�̓I�ȃ��X�N���������邽�߂ɁA�����ł͎����Ƃ��ĐƎ�ȃR���e�i�̐ݒ���܂�Pod�}�j�t�F�X�g��p����Kubernetes��Pod���f�v���C���A�R���e�i�̐ݒ肪�Ǝゾ�Ƃǂ̂悤�Ȃ��Ƃ��ł��Ă��܂��̂������Ă݂܂��傤�B

�����Ӂ�

�@���̎����͕K�����؊‹��ȂǑ��̃T�[�r�X�ɉe���̂Ȃ��‹��Ŏ��{���Ă��������B

�@�{���e�͌����ăT�C�o�[�U�����m�肷����̂ł͂���܂���̂ň��p�͂��Ȃ��ł��������B


�@�Ǝ�ȃR���e�i�̐ݒ���܂�Pod�}�j�t�F�X�g��p�ӂ��܂��B

apiVersion: v1
kind: Pod
metadata:
  name: exploit-pod
spec:
  hostPID: true
  containers:
  - name: ubuntu
    image: ubuntu:22.04
    command: ["/bin/sh", "-c", "while :; do sleep 10; done"]
    securityContext:
      privileged: true
exploit-pod.yaml

�@�����āA�p�ӂ���Pod�}�j�t�F�X�g��p����Kubernetes��Pod���f�v���C���Ă݂܂��B

$ kubectl apply -f exploit-pod.yaml
pod/exploit-pod created
 
$ kubectl get po
NAME                 READY   STATUS    RESTARTS      AGE
exploit-pod          1/1     Running   0             16s

�@�f�v���C������������A���̃R�}���h��Pod���̃R���e�i�ɐڑ����܂��B

$ kubectl exec -it exploit-pod -- /bin/bash
root@exploit-pod:/# hostname
exploit-pod

�@�R���e�i�ɐڑ��ł�����R���e�i���Ŏ��̂悤�ȃR�}���h�����s���Ă݂܂��B

root@exploit-pod:/# nsenter -t 1 -a /bin/bash
 
root@k8s-cluster-worker01:/# hostname
k8s-cluster-worker01
root@k8s-cluster-worker01:/# shutdown now

�@Kubernetes�Ƀf�v���C����Pod���̃R���e�i���o�R����Pod���N�����Ă���z�X�g�iKubernetes��Worker Node�j�ɐN�����A�z�X�g��ł̔C�ӂ̃R�}���h�����s������A�z�X�g�̃V���b�g�_�E�����ł����肵�Ă��܂��܂����B

�@�ڍׂȉ���͏ȗ����܂����A����̗�ł́uhostPID: true�v�uprivileged: true�v�̕������Ǝ�ȃR���e�i�̐ݒ�ɊY�����A���̂悤�Ȑݒ������Pod��Kubernetes�Ƀf�v���C�”\�ȏ�Ԃ��������Ƃŏ�L�̑��삪�”\�ɂȂ��Ă����Ƃ����܂��B

�R���e�i�Z�L�����e�B���m�ۂ��邽�߂�Kubernetes�����K�C�h���C���uPod Security Standards�v

�@��L�̂悤�ȃZ�L�����e�B���X�N�𔭐������Ȃ����߂ɂ́AKubernetes�ɐƎ�Ȑݒ�̃R���e�i���܂�Pod���f�v���C�����Ȃ����Ƃ��d�v�ł����A���������ǂ̂悤�ȃR���e�i�ݒ�Ȃ�u���S�v�Ƃ�����̂ł��傤���B

�@Kubernetes�̌����h�L�������g�ł́uPod Security Standards�v�Ƃ����K�C�h���C����񋟂��Ă��܂��B���̃K�C�h���C���ł͉��L��3��ނ̃|���V�[�ɉ������R���e�i�̐ݒ荀�ڂ��p�ӂ���Ă���A�����ɏ������邱�Ƃŏ���̃Z�L�����e�B���x�����m�ۂł��܂��B

�|���V�[ �T�v �ݒ荀�ڂ̗� �Z�L�����e�B���x��
Privileged �R���e�i�̐ݒ荀�ڂɋK���݂��Ȃ��|���V�[ - ��
Baseline �R���e�i�ւ̓����t�^�Ȃǃ��X�N�����m�Ȑݒ荀�ڂɂ‚��čŒ���K�肵���|���V�[ �E�R���e�i�ւ̓����t�^���֎~
�E�R���e�i�ƃz�X�g�Ԃł�Namespace��proc�̋��L���֎~
�EHostPath�̗��p���֎~
�EHostPort�̗��p���֎~
�ESysctls�ɂ���ĕύX�”\�ȃJ�[�l���p�����[�^�[�̐���
�E�R���e�i�ւ�Capability�t�^�̐���
�E�Z�L�����e�B�@�\�iAppArmor�ASELinux�ASeccomp�j�ɂ‚��ăZ�L�����e�B���x����ቺ������ݒ�̋֎~
��
Restricted �R���e�i�̎��s���[�U�[�ȂǏڍׂȐݒ荀�ڂ܂ł��K�肵���x�X�g�v���N�e�B�X�ɊY������|���V�[ �Eroot���[�U�[�ł̃R���e�i�N���̋֎~
�E�R���e�i���ł̓������i�̋֎~
�E�R���e�i�ւ�Capability�t�^�̋֎~�iNET_BIND_SERVICE�������j
�E�Z�L�����e�B�@�\�iSeccomp�j�̖����I�ȗL����
�E���p�”\��VolumeTypes�̐���
��

��Pod Security Standards�́uPrivileged�v�̓|���V�[�̃v���t�@�C�������������̂ŁA��قǂ̗�ŏo�Ă����R���e�i�ݒ�́uprivileged�v�Ƃ������ځi�R���e�i�ɑ΂�������t�^�j�Ƃ͕ʕ��Ȃ̂ł����ӂ��������B

�@�����̃|���V�[�ɂ‚��āA�x�X�g�v���N�e�B�X�́uRestricted�v�|���V�[�ɏ������邱�Ƃ��]�܂����ł����A���ꂪ����ꍇ�ł����ʂȗ��R���Ȃ�����͍Œ���uBaseline�v�|���V�[�ɏ�������Ƃ����ł��傤�B�V�X�e���R���|�[�l���g�Ȃ�Restricted�^Baseline�|���V�[�ɏ������邱�Ƃ�����ꍇ��Privileged�|���V�[��K�p���邱�ƂɂȂ�܂��B

�@�e�|���V�[�ŋ�̓I�ɂǂ̂悤�Ȑݒ肪��`����Ă��邩�ɂ‚��Ă�Pod Security Standards���m�F���Ă��������B

Kubernetes�ɂ�����|���V�[����

�@�u�Ǝ�ȃR���e�i�̐ݒ���܂�Pod��Kubernetes�Ƀf�v���C�����̂��ǂ̂悤�ȕ��@�Ŗh�����v�ɂ‚��Đ������܂��B

�@Kubernetes��Pod���f�v���C����ہA���̐ݒ��Pod Security Standards�̂悤�ȓ���̃|���V�[�ɏ���������d�g�݂���ʓI�Ɂu�|���V�[����v�Ƃ����܂��i�����ɂ̓R���e�i�̐ݒ�ɑ΂��鐧��͋��`�̃|���V�[����ɊY�����A�L�`�̃|���V�[����̓R���e�i�̐ݒ�ȊO�Ɋe��Kubernetes��̃��\�[�X�▽���K���Ȃǂɂ‚��Ă����䂷�邱�Ƃ��w���܂��j�B

�@�|���V�[����̒��ł��ݒ�������������ʁA�|���V�[�ɏ������Ă��Ȃ�Pod�̃f�v���C���֎~���邱�Ƃ��uValidation�v�A�|���V�[�ɏ������Ă��Ȃ�Pod�̐ݒ���㏑�����ċ����I�Ƀ|���V�[�ɏ��������邱�Ƃ��uMutation�v�Ƃ����܂��B

�@Kubernetes�ł�v1.3����uPod Security Policy�v�Ƃ���Built-in�̃|���V�[����̎d�g�݂����݂��Ă��܂������Av1.21�Ŕ񐄏��Ƃ��������ɂȂ�A�����v1.25�����[�X�������Đ�����Kubernetes�̋@�\����폜����܂����B

�@����ɑ΂���Kubernetes�����ł�Pod Security Policy�ɑ���|���V�[����̎��������Ƃ��āA�uOPA Gatekeeper�v�uKyverno�v�ɑ�\�����T�[�h�p�[�e�B�[�c�[����A����v1.25�Ő�����GA�ƂȂ���Kubernetes�Ƀr���g�C�����ꂽ�|���V�[����̎d�g�݁uPod Security Admission�v�̗��p���������Ă��܂��B�����v1.30�ł́A�C�ӂ�Validation�|���V�[���`���ēK�p�ł���uValidating Admission Policy�v���r���g�C���@�\�Ƃ��Ēlj�����܂����B

�R�����@Pod Security Policy�p�~�̔w�i

�@Pod Security Policy�ł͈ȑO�����Ɉȉ��̓_����莋����Ă���A�R�~���j�e�B�[�ł̋c�_�̌��ʁA�p�~�Ƃ������_�Ɏ����Ă��܂��B

  • Pod Security Policy�ł�User�܂���ServiceAccount�ɑ΂��ă|���V�[��t�^�ł��邪�A���̎d�l�ɂ���ă|���V�[���䂪���G�����A�Ӑ}�������䂪�ł��Ȃ��ꍇ������i�Ⴆ��User�ɓ���̃|���V�[�i�u�|���V�[A�v�Ƃ���j���t�^����Ă��Ȃ��ꍇ�ł��A�f�v���C����Pod�Ƀ|���V�[A���t�^���ꂽServiceAccount���o�C���h����Ă���΁A���ʂƂ���User�̓|���V�[A�ɏ�����Pod���f�v���C�ł��Ă��܂��j
  • �|���V�[��K�p����O�ɉe���m�F�iDry-run��Audit�j���ł��Ȃ��̂ŁA�|���V�[�K�p�ɔ����ė\�����ʉe���𐶂މ”\��������
  • User�܂���ServiceAccount�ɕ����̃|���V�[���t�^����Ă���ꍇ�ɗD�揇�ʂ��ݒ�ł��Ȃ�

�@�ڍׂȔp�~���R�ɂ‚��Ă�KEP-2579��Kubernetes Blog�Ɍf�ڂ���Ă���������̋L�����m�F���Ă��������B

�@����Pod Security Policy�ɂ��|���V�[������s���Ă���ꍇ�ɂ‚��ẮAPod Security Admission�ւ̈ڍs�K�C�h��Kubernetes�����h�L�������g�Œ񋟂���Ă���̂ŕ����Ċm�F���Ă��������B�ڍׂ̓����N��ɂ���܂����A�ڍs���̎�ȃ|�C���g�͎��̒ʂ�ł��B

  • Pod Security Policy�ւ̋@�\�ˑ��̊ϓ_����Pod Security Admission�Ɉڍs�”\���ǂ�������������
    Pod Security Admission�ɂ͌����_��Pod Security Policy�̂悤�Ƀ|���V�[���ڍׂɃJ�X�^�}�C�Y������AMutation�ɂ���Đݒ�������������肷��@�\���܂܂�Ă��Ȃ��̂ŁA�������l�����Ĉڍs�”\���ǂ������������A�ڍs�s�‚Ɣ��f�����ꍇ�̓T�[�h�p�[�e�B�[�c�[���̗��p����������
  • Pod Security Policy�ōs���Ă���|���V�[����̓��e��������
    Pod Security Admission�ł�Pod Security Standard�ɉ����Đ���iValidation�j���邱�ƂɂȂ�̂ŁAPod Security Policy�œ����̃|���V�[����ɂ��A�e�����m�F������ňڍs����
  • Namespace�ɑ΂��錠����������
    Pod Security Admission�ł̓|���V�[�̓K�p�Ώۂ�����Namespace�ɂȂ�̂ŁANamespace�ɑ΂��ēK�؂Ɍ����𐧌䂵�Ȃ��ƒN�ł��|���V�[��ύX�ł��Ă��܂����ƂɂȂ�

Pod Security Admission�ɂ��|���V�[����

�@����́Av1.25�Ő�����GA�ƂȂ����AKubernetes�Ƀr���g�C�����ꂽ�|���V�[����̎d�g�݁uPod Security Admission�v�̗��p�𐄏����Ă��܂��B�����v1.30�ł́A�C�ӂ�Validation�|���V�[���`���ēK�p�ł���uValidating Admission Policy�v���r���g�C���@�\�Ƃ��Ēlj�����܂����B�܂��AMutation�@�\��񋟂���uMutating Admission Policy�v��Kubernetes v1.32����alpha�łƂ��Ē񋟂���Ă��܂��B

�@�|���V�[�̓K�p�Ώۂ�Namespace����уN���X�^�S�̂ƂȂ��Ă���A�K�p�O�̎��O�m�F�iDry-run�j���”\�ł��B

�@Pod Security Admission�ł͉��L�\��3�‚̃��[�h���񋟂���Ă���A�e���[�h�ɑ΂���Pod Security Standards�̂����ꂩ�̃|���V�[���w�肵�܂��B�e���[�h�ɑ΂��ă|���V�[���w�肵�Ȃ������ꍇ�A���̃��[�h�ɂ͈ÖٓI��Privileged�iPod�̃f�v���C�𐧌����Ȃ��j���ݒ肳��邱�ƂɂȂ�܂��B

���[�h �|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ�̋���
enforce Pod�̃f�v���C���֎~����
audit Kubernetes��Audit Log�ɋL�^����iPod�̓f�v���C�����j
warn �x����\������iPod�̓f�v���C�����j

�@��������͋�̓I��Pod Security Admission�ɂ��|���V�[����̗�����Ă����܂��B

Namespace�ɑ΂��ă|���V�[��K�p����

�@��{�I�Ȏg�����Ƃ��āANamespace�ɑ΂��ă|���V�[��K�p���A�|���V�[������s���Ă݂܂��BNamespace�ɑ΂��ă|���V�[��K�p����ۂ́ANamespace��labels�Ŋe���[�h���ꂼ��ǂ̃��x���̃|���V�[��K�p���邩��ݒ肵�܂��B

�@���L�unamespace-a.yaml�v��Namespace�Ɋւ���}�j�t�F�X�g�ł��B���̃}�j�t�F�X�g�́ulabels�v������ƁA�uenforce�v���[�h�Ƃ���Baseline�|���V�[���A�uaudit�v�uwarn�v���[�h�Ƃ���Restricted�|���V�[���w�肵�Ă��邱�Ƃ�������܂��B

apiVersion: v1
kind: Namespace
metadata:
  name: namespace-a
  labels:
    # Baseline�|���V�[�Ɉᔽ����Pod�̃f�v���C���֎~
    pod-security.kubernetes.io/enforce: baseline
    pod-security.kubernetes.io/enforce-version: v1.31
    # Restricted�|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ��Audit Log�ɋL�^
    pod-security.kubernetes.io/audit: restricted
    pod-security.kubernetes.io/audit-version: v1.31
    # Restricted�|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ�͌x����\��
    pod-security.kubernetes.io/warn: restricted
    pod-security.kubernetes.io/warn-version: v1.31
namespace-a.yaml

�@����Namespace���ł́AKubernetes v1.31�ɂ�����Pod Security Standards�ɏ����āA���̂悤�ȃ|���V�[���䂪�s���܂��B

  • Baseline�|���V�[�Ɉᔽ����Pod�̃f�v���C���֎~����ienforce�j
  • Restricted�|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ��Audit Log�ɋL�^�iaudit�j����ьx����\���iwarn�j����

�@�{�e�ł�Kubernetes v1.31���_�ł̓��e���Љ�Ă��܂����APod Security Standards�̃|���V�[���e��Kubernetes�̃o�[�W�����A�b�v�ɂ���ĕύX����邱�Ƃ�����܂��i�Ⴆ�΃R���e�i�ւ�seccomp�Ɋւ���ݒ��v1.21�ł�Restricted�|���V�[�Ɋ܂܂�Ă��܂������Av1.22�ȍ~��Baseline�Ɋ܂܂��悤�ɂȂ�܂����j�B�ŐV�̏���Kubernetes��Web�T�C�g���m�F���Ă��������B

�@��L�̗�ł͖����I��v1.31�Ƃ����o�[�W������ݒ肵�Ă��܂����A�ulatest�v��ݒ肷�邱�Ƃŗ��p�”\�ȍŐV�o�[�W�����̃|���V�[���g����悤�ɂȂ�܂��B

�@����Kubernetes��ɂ͏�L�}�j�t�F�X�g��p���č쐬�����unamespace-a�v�ƁA���Ƀ|���V�[���w�肹���ɍ쐬�����unamespace-b�v�����݂��Ă���Ƃ��܂��B�����ɑ΂��Đ�̐����ŗp�����Ǝ�ȃR���e�i�̐ݒ���܂�Pod�}�j�t�F�X�g�uexploit-pod.yaml�v��K�p���APod���f�v���C���Ă݂܂��傤�B

# kubectl get ns
NAME                    STATUS   AGE
�c�c
namespace-a             Active   69s
namespace-b             Active   60s

�@namespace-a�ɑ΂��āA�ŏ��ɏЉ���Ǝ㐫���܂�exploit-pod.yaml��K�p���܂��B����ƁA���̂悤�ɃG���[���\������APod�̃f�v���C���֎~���ꂽ���Ƃ�������܂��B

# kubectl apply -f exploit-pod.yaml -n namespace-a
Error from server (Forbidden): error when creating "exploit-pod.yaml": pods "exploit-pod" is forbidden: violates PodSecurity "baseline:v1.31": host namespaces (hostPID=true), privileged (container "ubuntu" must not set securityContext.privileged=true)
 
# kubectl get po -n namespace-a
No resources found in namespace-a namespace.

�@�f�v���C���֎~���ꂽ�̂̓G���[���b�Z�[�W�ɂ��L�ڂ̒ʂ�A�f�v���C���悤�Ƃ���Pod�Ɋ܂܂��Ǝ�ȃR���e�i�̐ݒ�ihostPID: true�����privileged: true�j��Pod Security Standards��Baseline�|���V�[�Ɉᔽ��������ł��B

�@�ǂ��ᔽ���Ă���̂���Audit Log�Ŋm�F���Ă݂܂��傤�B

{
    "kind": "Event",
�c�c
    "responseStatus": {
        "metadata": {},
        "status": "Failure",
        "message": "pods \"exploit-pod\" is forbidden: violates PodSecurity \"baseline:v1.31\": host namespaces (hostPID=true), privileged (container \"ubuntu\" must not set securityContext.privileged=true)",
        "reason": "Forbidden",
        "details": {
            "name": "exploit-pod",
            "kind": "pods"
        },
        "code": 403
    },
    "requestReceivedTimestamp": "2024-08-25T14:37:11.624385Z",
    "stageTimestamp": "2024-08-25T14:37:11.634141Z",
    "annotations": {
        "authorization.k8s.io/decision": "allow",
        "authorization.k8s.io/reason": "",
        "pod-security.kubernetes.io/audit-violations": "would violate PodSecurity \"restricted:v1.31\": host namespaces (hostPID=true), privileged (container \"ubuntu\" must not set securityContext.privileged=true), allowPrivilegeEscalation != false (container \"ubuntu\" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container \"ubuntu\" must set securityContext.capabilities.drop=[\"ALL\"]), runAsNonRoot != true (pod or container \"ubuntu\" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container \"ubuntu\" must set securityContext.seccompProfile.type to \"RuntimeDefault\" or \"Localhost\")",
        "pod-security.kubernetes.io/enforce-policy": "baseline:v1.31"
    }
}

�@Pod Security Standards��Baseline�|���V�[�Ɉᔽ�������Ƃɂ����Pod�̃f�v���C�����ۂ��ꂽ���Ƃ��A�uresponseStatus�v�ŋL�^����Ă���̂�������܂��B�uannotations�v��Restricted�|���V�[�Ɉᔽ���Ă���|���L�^����Ă��܂��iAudit log�o�͌��ʂ�JSON�t�H�[�}�b�g�𐮌`������ԂŋL�ڂ��Ă��܂��j�B

��Kubernetes�ɂ�����Audit Log�̓f�t�H���g�Ŗ���������Ă���̂ŁA�L���ɂ������ꍇ��Kubernetes�����h�L�������g�ɉ����Đݒ肷��K�v������܂��B

�@������exploit-pod.yaml����uhostPID: true�v�uprivileged: true�v�̐ݒ�����O���A���̂悤��Pod�}�j�t�F�X�g��p�ӂ��܂��B

apiVersion: v1
kind: Pod
metadata:
  name: baseline-pod
spec:
  containers:
  - name: ubuntu
    image: ubuntu:20.04
    command: ["/bin/sh", "-c", "while :; do sleep 10; done"]
baseline-pod.yaml

�@��قǂƓ��l��namespace-a�ɑ΂���baseline-pod.yaml��K�p���Ă݂܂��B

# kubectl apply -f baseline-pod.yaml -n namespace-a
Warning: would violate PodSecurity "restricted:v1.31": allowPrivilegeEscalation != false (container "ubuntu" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "ubuntu" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "ubuntu" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "ubuntu" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
 
# kubectl get po -n namespace-a
NAME           READY   STATUS    RESTARTS   AGE
baseline-pod   1/1     Running   0          35s

�@����ƁA���x�̓G���[�ł͂Ȃ��x�����\������APod���̂͐���Ƀf�v���C���邱�Ƃ��ł��܂����BPod������Ƀf�v���C�ł����̂́A�uhostPID: true�v�uprivileged: true�v���R���e�i�̐ݒ肩�珜�O�������Ƃ�Baseline�|���V�[�ɏ�������悤�ɂȂ�������ł��B����A�ˑRRestricted�|���V�[�ɂ͏������Ă��Ȃ��̂ŁA���ʂƂ��Čx�����\������܂����B

�@Audit Log�ɂ‚��Ă��m�F���Ă݂�ƁA���L�̂悤��Restricted�|���V�[�Ɉᔽ���Ă���|��annotations�ɋL�^����Ă��邱�Ƃ�������܂��iAudit log�o�͌��ʂ�JSON�t�H�[�}�b�g�𐮌`������ԂŋL�ڂ��Ă��܂��j�B

{
    "kind": "Event",
�c�c
    "responseStatus": {
        "metadata": {},
        "code": 201
    },
    "requestReceivedTimestamp": "2024-08-25T14:47:23.225779Z",
    "stageTimestamp": "2024-08-25T14:47:23.239878Z",
    "annotations": {
        "authorization.k8s.io/decision": "allow",
        "authorization.k8s.io/reason": "",
        "pod-security.kubernetes.io/audit-violations": "would violate PodSecurity \"restricted:v1.31\": allowPrivilegeEscalation != false (container \"ubuntu\" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container \"ubuntu\" must set securityContext.capabilities.drop=[\"ALL\"]), runAsNonRoot != true (pod or container \"ubuntu\" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container \"ubuntu\" must set securityContext.seccompProfile.type to \"RuntimeDefault\" or \"Localhost\")",
        "pod-security.kubernetes.io/enforce-policy": "baseline:v1.31"
    }
}

�@���R�ł����A�|���V�[�������K�p����Ă��Ȃ�namespace-b�ɑ΂���exploit-pod.yaml��K�p���Č���ƁA�����Pod���f�v���C���邱�Ƃ��ł��܂��B

# kubectl apply -f exploit-pod.yaml -n namespace-b
pod/exploit-pod created
 
# kubectl get po -n namespace-b
NAME          READY   STATUS    RESTARTS   AGE
exploit-pod   1/1     Running   0          7s

Dry-run�ɂ��|���V�[�K�p�̉e���m�F

�@�^�p�őz�肳���P�[�X�Ƃ��āA���݂�namespace-b�̂悤�Ɂu����Pod���N�����Ă���Namespace�ɑ΂��ă|���V�[��K�p�������v�ꍇ���l�����܂��BPod Security Admission�ɂ��Validation��Pod�쐬���ɂ̂݋@�\����̂ŁA���̏�Ԃ�namespace-b��labels��t�^���ă|���V�[��L���ɂ��Ă��A�|���V�[�Ɉᔽ���Ă���exploit-pod�������ɒ�~����邱�Ƃ͂���܂���B

�@���R�ł����A�|���V�[�K�p��ɂ���Pod���č쐬���悤�Ƃ���΁A��̗ᓯ�l��Pod�̍쐬���֎~����܂��B�g���u���������Ӗ��ł��A���ꂩ��K�p���悤�Ƃ��Ă���|���V�[�Ɉᔽ���Ă���Pod��Namespace���ɑ��݂��Ȃ���Ԃɂ��Ă����ׂ��ł��B

�@���̍ۖ��ɗ��‚̂�Dry-run�@�\�ł��B���L�R�}���h�����s����ƁAnamespace-b��labels��t�^�����Ɂu�|���V�[��K�p�����ꍇ�ɁA�ǂ̂悤�ȃ|���V�[�ᔽ�����������邩�v�����O�Ɋm�F�ł��܂��B

# kubectl label --dry-run=server --overwrite ns namespace-b pod-security.kubernetes.io/enforce=baseline pod-security.kubernetes.io/enforce-version=v1.31
Warning: existing pods in namespace "namespace-b" violate the new PodSecurity enforce level "baseline:v1.31"
Warning: exploit-pod: host namespaces, privileged
namespace/namespace-b labeled
 
# kubectl get ns namespace-b --show-labels
NAME          STATUS   AGE    LABELS
namespace-b   Active   116m   kubernetes.io/metadata.name=namespace-b

�@����Pod���N�����Ă���Namespace�Ƀ|���V�[��K�p����ꍇ�A���̌��ʂ𓥂܂��āAPod�Ɋ܂܂��R���e�i�̐ݒ������������ōs���̂������ł��傤�B

Kubernetes�N���X�^�Ƀf�t�H���g�|���V�[���`����

�@1�–ڂ̗�ł͓����Namespace�ɑ΂��ă|���V�[��K�p���܂������A����Namespace���ƂɃ|���V�[��K�p����̂ł͂Ȃ��A�u�eNamespace��Kubernetes�N���X�^�Ƃ��Ē�`�����f�t�H���g�|���V�[���K�p�����悤�ɂ������v�P�[�X������ł��傤�B2�–ڂ̗�Ƃ��ẮAKubernetes�N���X�^�Ƀf�t�H���g�|���V�[���`���܂��B

�@Kubernetes�N���X�^�Ƀf�t�H���g�|���V�[���`����ۂ́A�uAdmissionConfiguration�v�Ƃ��ă|���V�[���`���܂��B

�@���L�upod-security.yaml�v��Kubernetes�N���X�^�̃f�t�H���g�|���V�[���`����AdmissionConfiguration�̐ݒ�t�@�C���ł��B�|���V�[�̓��e�Ƃ��ẮA1�–ڂ̗�Ɠ������Aenforce���[�h�Ƃ���Baseline�|���V�[���Aaudit�����warn���[�h�Ƃ���Restricted�|���V�[���w�肵�Ă��܂��B�f�t�H���g�|���V�[�̓K�p�����O����Namespace�Ƃ���kube-system��namespace-c���w�肵�Ă��܂��B

apiVersion: apiserver.config.k8s.io/v1
kind: AdmissionConfiguration
plugins:
- name: PodSecurity
  configuration:
    apiVersion: pod-security.admission.config.k8s.io/v1beta1
    kind: PodSecurityConfiguration
    defaults:
      enforce: "baseline"
      enforce-version: "v1.31"
      audit: "restricted"
      audit-version: "v1.31"
      warn: "restricted"
      warn-version: "v1.31"
    exemptions:
      # �f�t�H���g�|���V�[��K�p���Ȃ����[�U�[���w�肷��
      usernames: []
      # �f�t�H���g�|���V�[��K�p���Ȃ�RuntimeClass���w�肷��
      runtimeClasses: []
      # �f�t�H���g�|���V�[��K�p���Ȃ�Namespace���w�肷��
      namespaces:
        - kube-system
        - namespace-c
pod-security.yaml

�@AdmissionConfiguration�Ńf�t�H���g�|���V�[���`����ۂ́A�|���V�[�̓K�p���O�ΏۂƂ���User�ANamespace�ARuntimeClass���w��ł��܂��B

���Ȃ��A�uRuntimeClass�v��Pod�N�����Ɏg�p����OCI�����^�C���i�჌�x���R���e�i�����^�C���j��I������Kubernetes�̋@�\�ł��B�f�t�H���g��OCI�����^�C���irunc�Ȃǁj�ȊO��OCI�����^�C���i�ugVisor�v�uKata Container�v�Ȃǁj�𗘗p����ۂɎw�肵�܂��B

�@�ukube-proxy�v�Ȃ�Kubernetes���\������V�X�e���R���|�[�l���g�́A���̎d�l��Pod Security Standards�̃|���V�[�ɏ������Ă��Ȃ��P�[�X������̂ŁA��L�̗�ł́ukube-system Namespace�v���f�t�H���g�|���V�[�̓K�p�Ώۂ��珜�O���Ă��܂��B���ɂ��A�f�t�H���g�|���V�[���S�Ă�Pod�ɓK�p�����ƁA�Ď��R���|�[�l���g��CNI�iContainer Network Interface�j�ACSI�iContainer Storage Interface�j��DaemonSet�ȂǁA�����������K�v��Pod�����삵�Ȃ��Ȃ�ꍇ������܂��B���̂��߁A�f�t�H���g�|���V�[���`����ۂ͐�قǏЉ��Dry-run�̋@�\��p���Ď��O�ɉe�����m�F���A�K�v�ɉ����ăf�t�H���g�|���V�[�̓K�p���O��ݒ肷��Ƃ����ł��傤�B

�@AdmissionConfiguration��Kubernetes�N���X�^�ɓK�p����ɂ́A�ukube-apiserver�v�̋N���I�v�V�����u--admission-control-config-file�v�ŁA��L��pod-security.yaml���w�肵�܂��B����ɂ���āAKubernetes�N���X�^�Ƀf�t�H���g�|���V�[���ݒ肳��܂��B

�@���L�u/etc/kubernetes/manifests/kube-apiserver.yaml�v��kubeadm�ō\�z����Kubernetes�N���X�^��kube-apiserver�ɑ΂��Đݒ肷���ł��B

kubeadm�ł�kube-apiserver��Control Plane Node��ɁuStatic Pod�v�Ƃ��ăf�v���C�����̂ŁAControl Plane Node��ɑ��݂���kube-apiserver��Pod�}�j�t�F�X�g�Ɏ��̂悤�Ȑݒ��lj����邱�ƂŎ����I��Pod���č쐬����AAdmissionConfiguration���ǂݍ��܂�܂��B

apiVersion: v1
kind: Pod
metadata:
�c�c
  name: kube-apiserver
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-apiserver
�c�c
    - --admission-control-config-file=/etc/kubernetes/policies/pod-security.yaml
�c�c
    volumeMounts:
    - mountPath: /etc/kubernetes/policies
      name: policies
      readOnly: true
�c�c
  volumes:
  - name: policies
    hostPath:
      path: /etc/kubernetes/policies
      type: DirectoryOrCreate
�c�c
/etc/kubernetes/manifests/kube-apiserver.yaml

��Pod Security Admission��kube-apiserver�́uAdmission Controller�v�Ɋ܂܂��uPodSecurity Plugin�v�ɂ���Ď�������Ă��܂��B���̂��߁AAdmission Controller��ݒ肷��AdmissionConfiguration�t�@�C����PodSecurity Plugin��ݒ肵�܂��B

�@�ݒ肪����������AKubernetes�N���X�^�Ƀf�t�H���g�|���V�[����`���ꂽ���ǂ������m�F���܂��B1�–ڂ̗��namespace-b�ɂ͌•ʂŃ|���V�[��K�p���Ă��Ȃ��̂�exploit-pod.yaml��p���Đ����Pod���f�v���C�ł��܂������AKubernetes�N���X�^�Ƀf�t�H���g�|���V�[���`������Ԃł͂ǂ��ł��傤���B

�@namespace-b�ɑ΂���exploit-pod.yaml��K�p���Ă݂�ƁA���̂悤�ɃG���[���\�������Pod�̃f�v���C���֎~���ꂽ���Ƃ�������܂��i������1�–ڂ̗��namespace-b��Pod���쐬����Ă���ꍇ�͈�x�폜���Ă�����{���Ă��������j�B

# kubectl apply -f exploit-pod.yaml -n namespace-b
Error from server (Forbidden): error when creating "exploit-pod.yaml": pods "exploit-pod" is forbidden: violates PodSecurity "baseline:v1.31": host namespaces (hostPID=true), privileged (container "ubuntu" must not set securityContext.privileged=true)
kubectl get po -n namespace-b
No resources found in namespace-b namespace.

�@Audit Log�ɂ‚��Ă͏ȗ����܂����A1�–ڂ̗�Ɠ��l�̓��e���o�͂���Ă���͂��ł��B

�@�����ăf�t�H���g�|���V�[�œK�p���O�ΏۂƂ��Ďw�肵���unamespace-c�v���쐬���A���l��exploit-pod.yaml��K�p���Ă݂܂��Bnamespace-c�̓f�t�H���g�|���V�[���K�p���ꂸ�A�•ʂŃ|���V�[���K�p���Ă��Ȃ��̂ŁA���̒ʂ�A�����Pod���f�v���C�ł��܂����B

# kubectl create ns namespace-c
namespace/namespace-c created
 
# kubectl apply -f exploit-pod.yaml -n namespace-c
pod/exploit-pod created
 
# kubectl get po -n namespace-c
NAME          READY   STATUS    RESTARTS   AGE
exploit-pod   1/1     Running   0          20s

�@�Ō�ɁA���L�unamespace-d�v�Ɏ����悤�ȃf�t�H���g�|���V�[�����ɂ��|���V�[��K�p�����ꍇ�����Ă݂܂��B�f�t�H���g�|���V�[��namespace-d�ɓK�p�����|���V�[�ł͂ǂ��炪�D�悳���̂ł��傤���B

apiVersion: v1
kind: Namespace
metadata:
  name: namespace-d
  labels:
    # Privileged�|���V�[�iPod�̃f�v���C�𐧌����Ȃ��j
    pod-security.kubernetes.io/enforce: privileged
    pod-security.kubernetes.io/enforce-version: v1.31
    # Baseline�|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ��Audit Log�ɋL�^
    pod-security.kubernetes.io/audit: baseline
    pod-security.kubernetes.io/audit-version: v1.31
    # Baseline�|���V�[�Ɉᔽ����Pod�̃f�v���C�����m�����ꍇ�͌x����\��
    pod-security.kubernetes.io/warn: baseline
    pod-security.kubernetes.io/warn-version: v1.31
namespace-d.yaml

�@namespace-d�ɑ΂���exploit-pod.yaml��K�p����ƁA���̂悤�ɁAnamespace-d�ɓK�p�����|���V�[�ɏ]���āuPod�͐���Ƀf�v���C����‚‚��ABaseline�|���V�[�ɏ������Ă��Ȃ��v�|���x���Ƃ��ĕ\�������̂�������܂��B

kubectl apply -f exploit-pod.yaml -n namespace-d
Warning: would violate PodSecurity "baseline:v1.31": host namespaces (hostPID=true), privileged (container "ubuntu" must not set securityContext.privileged=true)
pod/exploit-pod created
 
kubectl get po -n namespace-d
NAME          READY   STATUS    RESTARTS   AGE
exploit-pod   1/1     Running   0          9s

�@���̂悤�ɁA�f�t�H���g�|���V�[����`����Ă����Ԃ�Namespace�Ɍ•ʂ̃|���V�[��K�p�����ꍇ�́ANamespace�̃|���V�[���D�悳��܂��B

�R�����@�T�[�h�p�[�e�B�[�c�[���̗��p

�@�|���V�[��������{����ɓ������āA�g�D�ɂ���Ă͎��̂悤�ȗv���𖞂��������P�[�X���������邱�Ƃ�����Ǝv���܂��B

  1. Kubernetes�̃}�j�t�F�X�g���|���V�[�Ɉᔽ���Ă���ꍇ�A�����I�Ƀ|���V�[�ɏ�������悤�ɓ��e��ύX���ăf�v���C�������iMutation�j
  2. Pod Security Standard�ɂȂ��Ǝ��̃|���V�[���`���ă|���V�[������������

�@�����������P�[�X�ɑΉ�����K�v������ꍇ�́A��q��OPA Gatekeeper��Kyverno�ɑ�\�����T�[�h�p�[�e�B�[�c�[����AValidation Admission Policy/Mutation Admission Policy�̗��p����������Ƃ悢�ł��傤�i��Mutation Admission Policy��v1.32���_�ŊJ�����ialpha�j�̃X�e�[�^�X�ł���A����ύX������”\��������̂Œ��ӂ��K�v�ł��j�B

�@�|���V�[����Ƃ͒��ڊ֌W������܂��񂪁AKubernetes�N���X�^�ɑ΂��ă}�j�t�F�X�g��K�p����ȑO�ɁA���̃}�j�t�F�X�g�Ɋ܂܂��Ǝ�Ȑݒ���`�F�b�N�������P�[�X������Ǝv���܂��B

�@�����������ꍇ���{�A�ڑ�17���ŏЉ���uTrivy�v���͂��߂Ƃ����A�`�F�b�N�c�[����p����̂������ł��傤�B


�܂Ƃ�

�@Pod Security Admission��OPA Gatekeeper�ȂLj�ʓI�ȃT�[�h�p�[�e�B�[�c�[���ɂ͏_��̖ʂł͗����̂́AKubernetes Built-in�̎d�g�݂Ƃ��Ď�y�Ƀ|���V�[����������ł���Ƃ����ϓ_����L�p���Ǝv���܂��B�]����Pod Security Policy�Ɣ�r���Ă��g��������r�I�V���v����������A���p�҂��|���V�[���`����K�v���Ȃ�������Ƃ������_����A�|���V�[�����Kubernetes�ɓ�������n�[�h�������Ȃ�Ⴍ�Ȃ����Ƃ����܂��B

�@���݉^�p���Ă���Kubernetes�N���X�^�ւ̃Z�L�����e�B�΍�Ƃ��āu�܂���������{���悤�v�Ɩ����Ă���ꍇ�́A���̋@���Pod Security Admission�̗��p���������Ă݂Ă͂������ł��傤���B

���X�V����

�y2024/12/17�zKubernetes v1.31�ɍ����悤�ɍX�V���܂����B


Copyright © ITmedia, Inc. All Rights Reserved.

'; if( !this.isSubscription ) { this.insertTarget = document.querySelector('#cmsBody .subscription') || document.querySelector('#cmsBody .inner'); } }; BodyAdIMSWithCCE.prototype = Object.create(BodyAdContent.prototype); BodyAdIMSWithCCE.prototype.activate = function () { refreshGam('InArtSpecialLink'); } // global reference window.itm = itm; //entry point BodyAdEventBase.polyfill(); const bodyAdManager = BodyAdManager.getInstance(); bodyAdManager.addEventListener(BodyAdManager.EVENTS.READY, function (ev) { bodyAdManager.loadAdvertise(); }); bodyAdManager.init(); })();
�X�|���T�[����̂��m�点PR

���ڂ̃e�[�}

4AI by IT - AIAAA
Microsoft  WindowsőO2025
AI for GWjAO
[R[h^m[R[h Zg by IT - ITGWjArWlX̒SŊ􂷂gD
Cloud Native Central by IT - XP[uȔ\͂gD
�V�X�e���J���m�E�n�E �y�����i�r�zPR
���Ȃ��ɂ������߂̋L��PR

RSS�ɂ‚���

�A�C�e�B���f�B�AID�ɂ‚���

���[���}�K�W���o�^

��IT�̃��[���}�K�W���́A �������A���ׂĖ����ł��B���Ѓ��[���}�K�W�������w�ǂ��������B