Skip to content

Security scan failure: Private keys stored in image #557

Open

Description

@vitaliyatoptus

Issue description:
We are using security scanning tool and it is currently flagging this project due to it's inclusion of a private key in server.key and client.key.
I understand that this is a false positive as mentioned key are used for tests only. However it is pretty hard to tweak security tool to ignore this particular issue and keep ensuring people do not put actual keys to the image.
I've found similar ticket in nodejs node-gyp module nodejs/node-gyp#2037 where they ended up extracting keys to the js file certs.js. I understand that it does not solve the issue however it tricks security scan and resolves mentioned false-positive.
Do you think similar thing (e.g. inlining key to the code) can be done here?

Steps to reproduce:
Run security scanning tool on the image that contains python-ldap project.

Operating system:
RHEL8 (I doubt it matters)

Python version:
3.9 (I doubt it matters)

python-ldap version:
latest (as of 15 Feb 2024)

Activity

  1. tiran commented on Feb 15, 2024

    @tiran
    Member

    Is your tool able to ignore files based on file patterns? We could rename the files to test-client.key and test-server.key if that helps.

  2. vitaliyatoptus commented on Feb 19, 2024

    @vitaliyatoptus
    Author

    Based on my information the tool does not allow to ignore based on patterns and even if it does in a corporate world it will be merely impossible to get this approved. I've asked the security team and I will update here once I get the answer.

  3. kramar11 commented on May 29, 2024

    @kramar11

    Same here. A trivy scan reports severity HIGH for the private keys included in the package:

    /app/.venv/lib/python3.11/site-packages/slapdtest/certs/client.key (secrets)
    ============================================================================
    Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 1, CRITICAL: 0)
    
    HIGH: AsymmetricPrivateKey (private-key)
    ════════════════════════════════════════
    Asymmetric Private Key
    ────────────────────────────────────────
    /app/.venv/lib/python3.11/site-packages/slapdtest/certs/client.key:1 (added by 'COPY /app /app # buildkit')
    
    
    /app/.venv/lib/python3.11/site-packages/slapdtest/certs/server.key (secrets)
    ============================================================================
    Total: 1 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 1, CRITICAL: 0)
    
    HIGH: AsymmetricPrivateKey (private-key)
    ════════════════════════════════════════
    Asymmetric Private Key
    ────────────────────────────────────────
     /app/.venv/lib/python3.11/site-packages/slapdtest/certs/server.key:1 (added by 'COPY /app /app # buildkit')
    

    Maybe best solution would be to not include slapdtest module with the python-ldap package, but rather make it optional or even a separate package?

  4. tiran commented on May 29, 2024

    @tiran
    Member

    That would take a large, backwards incompatible change.

    It's very common to have test keys and test certificates in a project. It would be more reasonable if you could work with your vendor and figure out a general solution that works for OSS project.

  5. kramar11 commented on Jun 25, 2024

    @kramar11

    Sorry for late reply!

    I understand that this would be backwards incompatible. But as automatic security scans in CI/CD pipelines are very common these days, you should maybe considering putting slapdtest in a separate package in a next major release where backwards compatibility isn't strictly required.

    My solution so far ist, to simply remove the slapdtest folder in my container, i.e. in Dockerfile I have:

    RUN rm -rf .venv/lib/python*/site-packages/slapdtest
    

    Maybe this can help someone who has the same problem and finds this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions