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

Beats: Using secureSettings with hostPath fails without runAsUser: 0 #6600

Open
naemono opened this issue Mar 27, 2023 · 4 comments
Open

Beats: Using secureSettings with hostPath fails without runAsUser: 0 #6600

naemono opened this issue Mar 27, 2023 · 4 comments
Labels
>bug Something isn't working

Comments

@naemono
Copy link
Contributor

naemono commented Mar 27, 2023

related #6156
and potentially related #6599 (If we want to try and automatically handle this scenario)

When using secureSettings with hostPath fails on elastic-internal-init-keystore initContainer without setting runAsUser: 0.

logs

❯ kc logs -n default eck-beats-beat-filebeat-xgkfx elastic-internal-init-keystore
Initializing keystore.
+ echo 'Initializing keystore.'
+ filebeat keystore create --force
error initializing beat: failed to create Beat meta file: open /usr/share/filebeat/data/meta.json.new: permission denied

Manifest

apiVersion: beat.k8s.elastic.co/v1beta1
kind: Beat
metadata:
  name: eck-beats
  namespace: default
spec:
  config:
    filebeat.inputs:
    - paths:
      - /var/log/containers/*.log
      type: container
    output.elasticsearch.hosts:
    - https://my-elasticsearch.gcp.elastic-cloud.com
    output.elasticsearch.username: elastic
    processors:
    - add_host_metadata: {}
    - add_cloud_metadata: {}
  daemonSet:
    podTemplate:
      spec:
        automountServiceAccountToken: true
        containers:
        - name: filebeat
          securityContext:
            runAsUser: 0
          volumeMounts:
          - mountPath: /var/log/containers
            name: varlogcontainers
          - mountPath: /var/log/pods
            name: varlogpods
          - mountPath: /var/lib/docker/containers
            name: varlibdockercontainers
        dnsPolicy: ClusterFirstWithHostNet
        hostNetwork: true
        terminationGracePeriodSeconds: 30
        volumes:
        - hostPath:
            path: /var/log/containers
          name: varlogcontainers
        - hostPath:
            path: /var/log/pods
          name: varlogpods
        - hostPath:
            path: /var/lib/docker/containers
          name: varlibdockercontainers
  secureSettings:
  - secretName: elasticsearch-credentials
  type: filebeat
  version: 8.6.1
@naemono naemono added the >bug Something isn't working label Mar 27, 2023
@naemono
Copy link
Contributor Author

naemono commented Mar 28, 2023

May be same issue as #6280 . I thought this was keystore related. I'll verify.

@ebuildy
Copy link

ebuildy commented Apr 25, 2023

this is a serious security issue, most of good security practices prevent to run container as root.

A quick (and dirty) fix is to use an init container to chown:

initContainers:
- command:
  - sh
  - -c
  - chown -R 1000:1000 /usr/share/metricbeat/data
  image: docker.elastic.co/beats/metricbeat:{{ $values.version }}
  imagePullPolicy: IfNotPresent
  name: permissions
  securityContext:
    runAsUser: 0
  volumeMounts:
  - mountPath: /usr/share/metricbeat/data
    name: beat-data

or to setup the file-system via provisionning tools like Ansible, is it possible to configure this path when deploying the metricbeat instance ?

@ebuildy
Copy link

ebuildy commented Apr 26, 2023

ho cant change the host path https://github.com/elastic/cloud-on-k8s/blob/main/pkg/controller/agent/pod.go#L429 or even use an emptyDir volume :-/

@ebuildy
Copy link

ebuildy commented Apr 28, 2023

BTW we should not generate the keystore file (sensitive data) on host volume! The keystore file should be stored on an emptyDir volume.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants