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

--policies=* does not appear to be working #55

Closed
stefansedich opened this issue Dec 18, 2019 · 10 comments · Fixed by #64
Closed

--policies=* does not appear to be working #55

stefansedich opened this issue Dec 18, 2019 · 10 comments · Fixed by #64

Comments

@stefansedich
Copy link

stefansedich commented Dec 18, 2019

Given the following deployment:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: opa
  namespace: opa
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: opa
    spec:
      containers:
      - name: opa
        image: openpolicyagent/opa
        args:
        - "run"
        - "--server"
        ports:
        - name: http
          containerPort: 8181
      - name: kube-mgmt
        image: openpolicyagent/kube-mgmt:0.10
        args:
          - --enable-policies=true
          - --policies=*
          - --require-policy-label=true

And given the following configmap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: test
  namespace: test
  labels:
    openpolicyagent.org/policy: rego
data:
  test.rego: |
    package kubernetes

    example = "Hello, Kubernetes!"

kube-mgmt does not appear to be loading the configmap at all, if I were to set --policies=test with an explicit namespace it will load the configmaps fine.

I was under the impression that --policies=* will load from any namespace?

@ashutosh-narkar
Copy link
Member

Yes with --policies=* kube-mgmt should look for policies in all namespaces. Since you also specified --require-policy-label=true, have you also labelled the configmaps in the other namespaces ?

@stefansedich
Copy link
Author

Yup I had done that @ashutosh-narkar, I could only get it to pick up poliies when using --policies=a,b,c and being explicit with namespaces.

@stefansedich
Copy link
Author

stefansedich commented Jan 15, 2020

@ashutosh-narkar could I be missing anything else here? have tried various things and had no luck with --policies=* it is working only if I use --policies with an explicit namespace.

@ashutosh-narkar
Copy link
Member

You can remove --enable-policies=true as it's true by default (https://github.com/open-policy-agent/kube-mgmt/blob/master/cmd/kube-mgmt/main.go#L71). Also may be try enclosing the arguments in quotes eg "--policies=*". Let me know if this doesn't work and I can try this out.

@stefansedich
Copy link
Author

No luck @ashutosh-narkar, no combination of quotes gets it working using --policies=* but as soon as I change it to --policies=test being the namespace my policy is in it loads it fine.

@ashutosh-narkar
Copy link
Member

Ok @stefansedich , I will try this out too.

@patoarvizu
Copy link

I'm seeing similar behavior but it seems to be inconsistent. One thing I noticed that I could kind of consistently reproduce but didn't make sense is that if I launch with --policies=* --require-policy-label=false, it won't discover policies even if they're in the opa namespace and have openpolicyagent.org/policy: rego on the ConfigMap. However, if I then set --require-policy-label=false, the ConfigMaps did get the openpolicyagent.org/policy-status: '{"status":"ok"}' annotation. It doesn't make sense that switch from enforcing the label no not enforcing it will suddenly make it work.

I couldn't reproduce this behavior consistently, but I seemed to be able to reproduce it very often. I was applying changes and checking the objects in quick succession, so it's possible there some race condition that made the behavior inconsistent.

I tested on both 0.10 and 0.11, on Kubernetes (k3s) 1.15. I can try running more tests later if I have time.

@ashutosh-narkar
Copy link
Member

Thanks @patoarvizu for helping to reproduce the issue. Sorry about the delay in looking into this. I'll try to reproduce this myself tomorrow.

@ashutosh-narkar
Copy link
Member

I could reproduce the issue and the implementation for the --policies=* feature doesn't seem to be doing what it's supposed to. Working on fix for it.

ashutosh-narkar added a commit to ashutosh-narkar/kube-mgmt that referenced this issue Jan 30, 2020
When kube-mgmt was started with the "--policies=*" option, it would set the array of namespaces with an emtpy string as its only element. This would break the logic of how namespaces are matched thereby not annotating configmaps containing policy and hence policies would not be loaded.

Fixes: open-policy-agent#55
Signed-off-by: Ashutosh Narkar <[email protected]>
@ashutosh-narkar
Copy link
Member

ashutosh-narkar commented Jan 30, 2020

PR: #64.

As mentioned in the PR commit, the --policies=* option was breaking the config map matching logic. It would appear to work (mistakenly) in cases where --policies=* is set and --require-policy-label=false but the config map had the label openpolicyagent.org/policy=rego. This behavior was observed by @patoarvizu as well.

Also it would be recommended to use the --require-policy-label=true option in conjunction with --policies=*. You would also need to give OPA/kube-mgmt a ClusterRole that allows it to annotate config maps in all namespaces.

ashutosh-narkar added a commit that referenced this issue Jan 30, 2020
When kube-mgmt was started with the "--policies=*" option, it would set the array of namespaces with an emtpy string as its only element. This would break the logic of how namespaces are matched thereby not annotating configmaps containing policy and hence policies would not be loaded.

Fixes: #55
Signed-off-by: Ashutosh Narkar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants