Skip to content

Symbolic links are not loaded as projects #1102

Closed

Description

@maanur

Environment

Sentry SaaS (sentry.io)
Relay is running on OpenShift 4.7.31 with the image:
docker.io/getsentry/relay@sha256:d6d471ec789dd046d9807fca03bfa9b94b8d0ccb67ce85fed1668c8de4de5630

Steps to Reproduce

  1. Create new config with "static" mode, add <project_id>.json to project directory.
  2. Wrap config.yaml and projects directory to ConfigMaps.
  3. Mount them with the following deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: sentry-relay
  labels:
    app.kubernetes.io/name: sentry-relay
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: sentry-relay
  template:
    metadata:
      labels:
        app.kubernetes.io/name: sentry-relay
    spec:
      volumes:
        - name: config
          configMap:
            name: sentry-relay-config
        - name: projects
          configMap:
            name: sentry-relay-projects
      containers:
        - name: sentry-relay
          image: docker.io/getsentry/relay:latest
          args:
            - run
            - "--config"
            - "/etc/relay"
          volumeMounts:
            - name: config
              mountPath: /etc/relay
            - name: projects
              mountPath: /etc/relay/projects

Expected Result

Relay starts with the provided config and reads projects from /etc/sentry/projects

Actual Result

Relay spams WARN log messages:

2021-10-20T23:12:35Z [relay_server::actors::project_local] WARN: skipping "/etc/relay/projects/..2021_10_20_22_46_00.150511719", not a file
2021-10-20T23:12:35Z [relay_server::actors::project_local] WARN: skipping "/etc/relay/projects/59*****.json", not a file
2021-10-20T23:12:35Z [relay_server::actors::project_local] WARN: skipping "/etc/relay/projects/..data", not a file

(valid Project ID under the stars)

Those files are symlinks in fact:

$ ls -al /etc/relay/projects
total 0
drwxrwsrwx. 3 root 1000660000 79 Oct 20 22:46 .
drwxrwsrwx. 4 root 1000660000 93 Oct 20 22:46 ..
drwxr-sr-x. 2 root 1000660000 26 Oct 20 22:46 ..2021_10_20_22_46_00.150511719
lrwxrwxrwx. 1 root root       31 Oct 20 22:46 ..data -> ..2021_10_20_22_46_00.150511719
lrwxrwxrwx. 1 root root       19 Oct 20 22:46 5910073.json -> ..data/5910073.json

Activity

  1. RaduW commented on Oct 21, 2021

    @RaduW
    Contributor

    Thank you for raising this issue, we are looking into it.

  2. elliotcourant commented on Nov 14, 2021

    @elliotcourant

    I have a terrible way of getting around this as a stop gap; I did not want our logs being filled up with these messages so I approached it like this:

          volumes:
            - name: config
              configMap:
                name: relay
                optional: false
            - name: projects
              configMap:
                name: relay-projects
                optional: false
            - name: work
              emptyDir: { }
          initContainers:
            - name: setup
              image: busybox
              command:
                - /bin/sh
                - -c
                - "cp /tmp/sentry/config/* /tmp/sentry/relay/ && mkdir /tmp/sentry/relay/projects && cp /tmp/sentry/projects/* /tmp/sentry/relay/projects/"
              volumeMounts:
                - mountPath: /tmp/sentry/config
                  name: config
                - mountPath: /tmp/sentry/projects
                  name: projects
                - mountPath: /tmp/sentry/relay
                  name: work
          containers:
            - name: relay
              image: getsentry/relay
              args:
                - run
                - --config
                - /work/.relay
              env:
                - name: RELAY_PORT
                  value: '3000'
              ports:
                - containerPort: 3000
              workingDir: /work
              volumeMounts:
                - mountPath: /work/.relay
                  name: work

    The downside to this is that if relay was able to recognize configmap changes without restarting (see that the file changed) this will break that behavior (configmap changes now require rolling the pod). But it does silence the warnings.

    Not sure if this is helpful at all for anyone, but ended up working for me as a stopgap solution.

  3. AliMirlou commented on Jan 4, 2023

    @AliMirlou

    @elliotcourant
    I had the same issue and came up with this exact solution but it was really annoying.
    I looked into the relay code a bit though. I'm not a rust developer but it seemed like there is a better approach in checking the files than what has been implemented right now.

    Currently, is_file is being used to check whether it's a file:

    while let Some(entry) = directory.next_entry().await? {
    let path = entry.path();
    if !entry.metadata().await?.is_file() {
    relay_log::warn!("skipping {:?}, not a file", path);
    continue;
    }

    But this method returns false for any symbolic links, as documented here:

    Returns true if this metadata is for a regular file. The result is mutually exclusive to the result of Metadata::is_dir, and will be false for symlink metadata obtained from symlink_metadata.

    The document also suggests this approach though, which I feel like makes sense in this scenario:

    When the goal is simply to read from (or write to) the source, the most reliable way to test the source can be read (or written to) is to open it. Only using is_file can break workflows like diff <( prog_a ) on a Unix-like system for example. See File::open or OpenOptions::open for more information.

  4. added this to the Maintenance milestone on Feb 2, 2023
  5. added
    enhancement
    filler
    and removed on Feb 3, 2023
  6. self-assigned this
    on Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementfiller

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions