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

Teleport Kubernetes Operator supports Bot resource #34285

Open
Tracked by #34299
tuladhar opened this issue Nov 7, 2023 · 8 comments
Open
Tracked by #34299

Teleport Kubernetes Operator supports Bot resource #34285

tuladhar opened this issue Nov 7, 2023 · 8 comments
Labels
c-cv Internal Customer Reference c-cwv Internal Customer Reference c-ip Internal Customer Reference c-lo Internal Customer Reference c-upg Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements kube-operator Issues related to Kube Operator machine-id

Comments

@tuladhar
Copy link
Contributor

tuladhar commented Nov 7, 2023

What would you like Teleport to do?

Ability to add Bot resource using Teleport Kubernetes Operator, currently, it's only available via tctl:

tctl bots add my-bot --token my-bot-token --roles my-bot-role

What problem does this solve?

  • Automates addings bot through Teleport Kubernetes Operator.

If a workaround exists, please include it.

tctl bots add my-bot --token my-bot-token --roles my-bot-role
@tuladhar tuladhar added the feature-request Used for new features in Teleport, improvements to current should be #enhancements label Nov 7, 2023
@tuladhar tuladhar changed the title Teleport Kubernetes Operator supports for Bot Teleport Kubernetes Operator supports adding Bot Nov 7, 2023
@tuladhar tuladhar changed the title Teleport Kubernetes Operator supports adding Bot Teleport Kubernetes Operator supports Bot resource Nov 7, 2023
@strideynet strideynet added machine-id kube-operator Issues related to Kube Operator labels Nov 7, 2023
@strideynet
Copy link
Contributor

Likely dependent on #33808

@webvictim webvictim added the c-ip Internal Customer Reference label Jan 29, 2024
@TeleLos TeleLos added the c-cv Internal Customer Reference label Feb 22, 2024
@TeleLos
Copy link
Contributor

TeleLos commented Feb 22, 2024

Zendesk 9890 c-cv expressed that they try to manage all their Teleport roles via the Kubernetes operator. Adding this feature would be beneficial to their work flow.

@yair-segal
Copy link

We would also like to use this feature. Currently this is done manually with the tctl command, post Teleport k8s/helm deployment .

@MattiasAng
Copy link

Any update on this one? Having to workaround this with tctl commands is quite cumbersome in terms of scaling.

@milos-teleport milos-teleport added the c-lo Internal Customer Reference label Sep 5, 2024
@zmb3 zmb3 added the c-upg Internal Customer Reference label Sep 27, 2024
@bfeuillet
Copy link

bfeuillet commented Nov 26, 2024

Hey there,
On my side i'm using FluxCD to automate the deployment of kubernetes resources (helm & co) on my k8s clusters.
I recently deployed the teleport-operator to have role, users, tokens and co as code (yaml).

But like users in this thread, I'm obliged to use tctl one shoot manual command to create bot, would it be possible to create the teleport CRD for bot so the teleport-operator handle the deployment automatically ? (in a GitOps way)

Thanks!

@strideynet
Copy link
Contributor

Just an update - this ticket still remains blocked on a problem with an upstream dependency we use to build the Teleport Kubernetes Operator - kubernetes/kubernetes#124154

@kachi-app
Copy link

kachi-app commented Nov 27, 2024

I tried concat the yaml, and failed

# tbot-operator.yaml
kind: bot
version: v1
metadata:
  # name is a unique identifier for the bot in the cluster.
  name: tbot-operator
spec:
  # roles is a list of roles that the bot should be able to generate credentials
  # for.
  roles:
    - editor
    - mongodb-admin
    - operator

# Kustomize 
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: common

configMapGenerator:
  - name: tbot-operator-cm
    options:
      disableNameSuffixHash: true
    files:
      - tbot-operator.yaml=tbot-operator.yaml


# Teleport Cluster YAML
    ## Add tbot-operator for auto generate role
    extraVolumes:
      # Generated from ./configs/bots/kustomization.yaml
      - name: "tbot-operator-cm"
        configMap:
          name: "tbot-operator-cm"
      - name: "apply-on-startup"
        emptyDir: {}

    extraVolumeMounts:
      - name: tbot-operator-cm
        mountPath: /tbot
      - name: apply-on-startup
        mountPath: /opt/teleport

    initContainers:
      - name: "combine-tbot-operator"
        image: "alpine"
        command: [ "/bin/sh", "-c" ]
        args:
          - |
            echo "========================"
            echo "Show tbot-operator.yaml"
            echo "========================"
            cat /tbot/tbot-operator.yaml
            echo "========================"
            echo "Show apply-on-startup.yaml"
            echo "========================"
            cat /etc/teleport/apply-on-startup.yaml
            echo "================================================================================================"
            echo "Concat /tbot/tbot-operator.yaml to /etc/teleport/apply-on-startup.yaml"
            echo "================================================================================================"
            cat /tbot/tbot-operator.yaml /etc/teleport/apply-on-startup.yaml > /opt/teleport/apply-on-startup.yaml
            echo "========================"
            echo "After Merge"
            echo "========================"
            cat /opt/teleport/apply-on-startup.yaml
    extraArgs:
      - "--apply-on-startup=/opt/teleport/apply-on-startup.yaml"

@kachi-app
Copy link

Updates Workaround

apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: teleport-cluster
spec:
  releaseName: teleport-cluster
  chart:
    spec:
      chart: teleport-cluster
      sourceRef:
        kind: HelmRepository
        name: teleport
      version: "17.0.2"
  interval: 10m
# Patch the ClusterRole to allow patching the configmaps
  postRenderers:
    - kustomize:
        patches:
          - target:
              version: v1
              kind: ClusterRole
              name: teleport-cluster
            patch: |
              - op: add
                path: /rules/0
                value: { "apiGroups": [""], "resources": ["configmaps"], "resourceNames": ["teleport-cluster-auth"], "verbs": ["patch", "get", "update"] }

  values:
    ## Add tbot-operator for auto generate role
    extraVolumes:
      # Generated from ./configs/bots/kustomization.yaml
      - name: "tbot-operator-cm"
        configMap:
          name: "tbot-operator-cm"
      - name: "apply-on-startup"
        emptyDir: {}

    extraVolumeMounts:
      - name: tbot-operator-cm
        mountPath: /tbot
      - name: apply-on-startup
        mountPath: /opt/teleport

    initContainers:
      - name: "patch-tbot-operator"
        image: "bitnami/kubectl:latest"
        command: [ "/bin/sh", "-c" ]
        securityContext:
          runAsUser: 0 # Root user
          runAsGroup: 0
          allowPrivilegeEscalation: true
        env:
          - name: TELEPORT_APP_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
        command: [ "/bin/sh", "-c" ]
        args:
          - |
            if [ "$TELEPORT_APP_NAME" != "teleport-cluster-auth" ]; then
              echo "TELEPORT_APP_NAME is not equal to 'teleport-cluster-auth'. Exiting with status 0."
              exit 0
            fi
            echo "========================"
            echo "Show tbot-operator.yaml"
            echo "========================"
            cat /tbot/tbot-operator.yaml
            echo "========================"
            echo "Show apply-on-startup.yaml"
            echo "========================"
            cat /etc/teleport/apply-on-startup.yaml
            echo "========================"
            echo "Concat and Generate YAML"
            echo "========================"
            cat <<EOF > /opt/teleport/output.yaml
            data:
              apply-on-startup.yaml: |
            $(cat /etc/teleport/apply-on-startup.yaml | sed 's/^/    /')
                ---
            $(cat /tbot/tbot-operator.yaml | sed 's/^/    /')
            EOF
            
            apt-get update -y
            apt-get install yamllint -y
            
            cat <<EOF > /opt/teleport/.yamllint
            extends: default
            rules:
              document-start: disable  # Disable warnings for missing '---'
              line-length:
                max: 120               # Increase the maximum line length to 120 characters
                level: warning         # Change level to warning
            EOF
            
            yamllint --version
            cat /opt/teleport/.yamllint
            yamllint -c /opt/teleport/.yamllint /opt/teleport/output.yaml
            cat /opt/teleport/output.yaml
            
            cat /etc/os-release
            kubectl patch configmap teleport-cluster-auth -p "$(cat /opt/teleport/output.yaml)" --type=strategic -o yaml

Results:
Image
teleport-cluster-auth configmap

    ---
    kind: token
    version: v2
    metadata:
      name: "teleport-operator"
    spec:
      roles: [Bot]
      join_method: kubernetes
      bot_name: operator
      kubernetes:
        allow:
          - service_account: "teleport:teleport-cluster-operator"
    ---
    kind: bot
    version: v1
    metadata:
      # name is a unique identifier for the bot in the cluster.
      name: tbot-operator
    spec:
      # roles is a list of roles that the bot should be able to generate credentials
      # for.
      roles:
        - editor
        - mongodb-admin
        - operator

Notes:

  • After few minutes, the configmap will rollback to previous state without tbot-operator. However the bot is still there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-cv Internal Customer Reference c-cwv Internal Customer Reference c-ip Internal Customer Reference c-lo Internal Customer Reference c-upg Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements kube-operator Issues related to Kube Operator machine-id
Projects
None yet
Development

Successfully merging a pull request may close this issue.