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

In-Cluster Permission #273

Closed
kieronlanning opened this issue Mar 26, 2019 · 5 comments
Closed

In-Cluster Permission #273

kieronlanning opened this issue Mar 26, 2019 · 5 comments

Comments

@kieronlanning
Copy link

Is there a way to give a specific service access to certain parts of the cluster?

I'm trying to do some basic service discovery from a service - which simply lists other service currently available based on some labels.

However, trying to make that call from within the cluster itself results in a 403 - Forbidden.

I'm accessing the cluster like so: var config = KubernetesClientConfiguration.InClusterConfig();

@brendandburns
Copy link
Contributor

You need to look at (and configure) Service Account RBAC:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/

I'm going to close this since it is unrelated to the client library.

@kieronlanning
Copy link
Author

@brendandburns You put me on to exactly the right path - thankyou!

@richardgragasin
Copy link

@brendandburns You put me on to exactly the right path - thankyou!

Hi, were you able to configure service account RBAC? i'm currently facing similar issue

@kieronlanning
Copy link
Author

kieronlanning commented May 14, 2019

@richardgragasin Yes! We ended up with this:

open-api-rbac.yaml:

kind: ServiceAccount
metadata:
  name: open-api-account
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: open-api-service-reader
rules:
- apiGroups: [""]
  resources: ["services"]
  verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: open-api-service-reader
subjects:
  - kind: ServiceAccount
    # Reference to ServiceAccount kind's `metadata.name`
    name: open-api-account
    # Reference to ServiceAccount kind's `metadata.namespace`
    namespace: default
roleRef:
  kind: ClusterRole
  name: open-api-service-reader
  apiGroup: rbac.authorization.k8s.io

And then the Deployment kind looks a little like this:

Partial open-api-deployment.yaml:

kind: Deployment
metadata:
  name: open-api
  labels:
    name: open-api
    app: test-services
spec:
  strategy:
    type: RollingUpdate
  replicas: 1
  template:
    metadata:
      labels:
        name: open-api
        app: test-services
    spec:
      serviceAccountName: open-api-account
      containers:
      - name:  open-api
        image: open-api:$BUILD_ID

@richardgragasin
Copy link

@richardgragasin Yes! We ended up with this:

open-api-rbac.yaml:

kind: ServiceAccount
metadata:
  name: open-api-account
  namespace: default
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: open-api-service-reader
rules:
- apiGroups: [""]
  resources: ["services"]
  verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: open-api-service-reader
subjects:
  - kind: ServiceAccount
    # Reference to ServiceAccount kind's `metadata.name`
    name: open-api-account
    # Reference to ServiceAccount kind's `metadata.namespace`
    namespace: default
roleRef:
  kind: ClusterRole
  name: open-api-service-reader
  apiGroup: rbac.authorization.k8s.io

And then the Deployment kind looks a little like this:

Partial open-api-deployment.yaml:

kind: Deployment
metadata:
  name: open-api
  labels:
    name: open-api
    app: test-services
spec:
  strategy:
    type: RollingUpdate
  replicas: 1
  template:
    metadata:
      labels:
        name: open-api
        app: test-services
    spec:
      serviceAccountName: open-api-account
      containers:
      - name:  open-api
        image: open-api:$BUILD_ID

Great! let me try this one. i hope this will work on me.

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

No branches or pull requests

3 participants