megalinter icon indicating copy to clipboard operation
megalinter copied to clipboard

how can i run megalinter if my code has private dependencies?

Open buzzdan opened this issue 8 months ago • 6 comments

on my machine i can run "go mod download" which uses my ssh agent to resolve private deps. but when i try running "mega-linter-runner" it fails since it doesnt have access to private github repos.

i've already handled such cases with "docker build --ssh=default" but here im not sure what is the correct approach.

help would be appreciated 🙏

buzzdan avatar Mar 26 '25 15:03 buzzdan

@nvuillam any idea how to tackle this issue ?

buzzdan avatar Apr 07 '25 08:04 buzzdan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

github-actions[bot] avatar May 08 '25 01:05 github-actions[bot]

@buzzdan did you try PRE_COMMANDS ? :)

https://megalinter.io/latest/config-precommands/

nvuillam avatar May 08 '25 07:05 nvuillam

Since megalinter run inside a container i am looking for a way to use volumes to share my ssh key locally, or maybe pass it in as env var and use pre-commands to fetch it and add it to a local ssh agent

buzzdan avatar May 11 '25 19:05 buzzdan

@buzzdan do you have a full example of commands that you need to get your external private dependencies ? (With example variables that you would need ?)

With such info i'll try to find a way for you pass that to MegaLinter

nvuillam avatar May 11 '25 23:05 nvuillam

ok so lets say i have a Golang lib in my organization GitHub with internal/private privileges (github.com/org-name/internal-lib) the only way you can run go mod download is if you have an ssh key installed in your ssh-agent:

~/.ssh/config:

Host github.com
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

in order to make go know it needs to fetch ssh and not http we need to configure it to do so:

git config --global url."[email protected]:org-name/".insteadOf "https://github.com/org-name/"

now when i run go mod download it will start fetching dependencies and any org dep will be fetched via ssh using my own ssh key

in github actions i currently use deploy-keys which is also a set of ssh keys so in order to make megalinter work we need the ability to safely load the ssh keys inside the container maybe start the container with a shared volume or something like that.

i gave you an example in go but i know it can be an issue with any language. thank you 🙏

buzzdan avatar Jun 01 '25 08:06 buzzdan

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

github-actions[bot] avatar Jul 02 '25 01:07 github-actions[bot]

Commenting to keep it open 🙏

buzzdan avatar Jul 14 '25 16:07 buzzdan

@buzzdan if you need to share volumes, you need to call MegaLinter manually with docker run (and not use the Github action)

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:rw -v $(pwd):/tmp/lint:rw oxsecurity/megalinter:v8

https://megalinter.io/latest/install-docker/

Note: if you want to use integration, you'll have to add variables

Advanced example:

          docker run --rm \
            -e GITHUB_SHA=$GITHUB_SHA \
            -e GITHUB_REF=$GITHUB_REF \
            -e GITHUB_REPOSITORY=$GITHUB_REPOSITORY \
             [...+ all variables required by your integration......]
            -v /var/run/docker.sock:/var/run/docker.sock:rw \
            -v $(pwd):/tmp/lint:rw \
            oxsecurity/megalinter:v8

nvuillam avatar Jul 17 '25 14:07 nvuillam

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

github-actions[bot] avatar Aug 17 '25 01:08 github-actions[bot]