Skip to content

Commit

Permalink
Use PSP from policy API group.
Browse files Browse the repository at this point in the history
  • Loading branch information
php-coder committed Mar 1, 2018
1 parent 857fee8 commit 25cce34
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/admin/authorization/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ DELETE | delete (for individual resources), deletecollection (for collections

Kubernetes sometimes checks authorization for additional permissions using specialized verbs. For example:

* [PodSecurityPolicy](/docs/concepts/policy/pod-security-policy/) checks for authorization of the `use` verb on `podsecuritypolicies` resources in the `extensions` API group.
* [PodSecurityPolicy](/docs/concepts/policy/pod-security-policy/) checks for authorization of the `use` verb on `podsecuritypolicies` resources in the `policy` API group.
* [RBAC](/docs/admin/authorization/rbac/#privilege-escalation-prevention-and-bootstrapping) checks for authorization
of the `bind` verb on `roles` and `clusterroles` resources in the `rbac.authorization.k8s.io` API group.
* [Authentication](/docs/admin/authentication/) layer checks for authorization of the `impersonate` verb on `users`, `groups`, and `serviceaccounts` in the core API group, and the `userextras` in the `authentication.k8s.io` API group.
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/policy/example-psp.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: example
Expand Down
4 changes: 2 additions & 2 deletions docs/concepts/policy/pod-security-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ controller](/docs/admin/admission-controllers/#how-do-i-turn-on-an-admission-con
but doing so without authorizing any policies **will prevent any pods from being
created** in the cluster.

Since the pod security policy API (`extensions/v1beta1/podsecuritypolicy`) is
Since the pod security policy API (`policy/v1beta1/podsecuritypolicy`) is
enabled independently of the admission controller, for existing clusters it is
recommended that policies are added and authorized before enabling the admission
controller.
Expand Down Expand Up @@ -84,7 +84,7 @@ apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: <role name>
rules:
- apiGroups: ['extensions']
- apiGroups: ['policy']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames:
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/policy/privileged-psp.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: privileged
Expand Down
2 changes: 1 addition & 1 deletion docs/concepts/policy/restricted-psp.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: extensions/v1beta1
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
Expand Down
5 changes: 2 additions & 3 deletions docs/tutorials/clusters/apparmor.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,13 @@ node with the required profile.
### Restricting profiles with the PodSecurityPolicy

If the PodSecurityPolicy extension is enabled, cluster-wide AppArmor restrictions can be applied. To
enable the PodSecurityPolicy, two flags must be set on the `apiserver`:
enable the PodSecurityPolicy, the following flag must be set on the `apiserver`:

```
--admission-control=PodSecurityPolicy[,others...]
--runtime-config=extensions/v1beta1/podsecuritypolicy[,others...]
```

With the extension enabled, the AppArmor options can be specified as annotations on the PodSecurityPolicy:
The AppArmor options can be specified as annotations on the PodSecurityPolicy:

```yaml
apparmor.security.beta.kubernetes.io/defaultProfileName: <profile_ref>
Expand Down
22 changes: 17 additions & 5 deletions test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"testing"

policyv1beta1 "k8s.io/api/policy/v1beta1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/validation/field"
Expand Down Expand Up @@ -173,8 +174,8 @@ func validateObject(obj runtime.Object) (errors field.ErrorList) {
t.Namespace = api.NamespaceDefault
}
errors = ext_validation.ValidateIngress(t)
case *extensions.PodSecurityPolicy:
errors = ext_validation.ValidatePodSecurityPolicy(t)
case *policyv1beta1.PodSecurityPolicy:
errors = validatePodSecurityPolicy(t)
case *extensions.ReplicaSet:
if t.Namespace == "" {
t.Namespace = api.NamespaceDefault
Expand Down Expand Up @@ -312,9 +313,9 @@ func TestExampleObjectSchemas(t *testing.T) {
"nginx-deployment": {&extensions.Deployment{}},
},
"../docs/concepts/policy": {
"privileged-psp": {&extensions.PodSecurityPolicy{}},
"restricted-psp": {&extensions.PodSecurityPolicy{}},
"example-psp": {&extensions.PodSecurityPolicy{}},
"privileged-psp": {&policyv1beta1.PodSecurityPolicy{}},
"restricted-psp": {&policyv1beta1.PodSecurityPolicy{}},
"example-psp": {&policyv1beta1.PodSecurityPolicy{}},
},
"../docs/concepts/services-networking": {
"curlpod": {&extensions.Deployment{}},
Expand Down Expand Up @@ -754,3 +755,14 @@ func TestReadme(t *testing.T) {
}
}
}

// TODO: remove type conversion when PSP validation will accept PSP from policy group
func validatePodSecurityPolicy(newPsp *policy.PodSecurityPolicy) field.ErrorList {
oldPsp := &extensions.PodSecurityPolicy{}
if err := Convert_v1beta1_PodSecurityPolicy_To_extensions_PodSecurityPolicy(newPsp, oldPsp, nil); err != nil {
errs = field.ErrorList{}
errs = append(errors, field.InternalError(field.NewPath(""), fmt.Errorf("cannot convert PSP from policy to extensions group: %v", err)))
return errs
}
return ext_validation.ValidatePodSecurityPolicy(oldPsp)
}

0 comments on commit 25cce34

Please sign in to comment.