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

Support wildcard domains #236

Closed
jauderho opened this issue Jan 20, 2023 · 10 comments · Fixed by #292
Closed

Support wildcard domains #236

jauderho opened this issue Jan 20, 2023 · 10 comments · Fixed by #292

Comments

@jauderho
Copy link
Contributor

Microsoft publishes container images on mcr.microsoft.com for example. mcr.microsoft.com/dotnet/sdk:7.0

However, when building a Docker image using Github Actions, it appears that mcr.micrsoft.com resolves to multiple regions across different runs.

Observed:

  • westus.data.mcr.microsoft.com
  • westcentralus.data.mcr.microsoft.com

So instead of having to slowly track and whitelist individual regions, I'm hoping that you can just allowlist *.mcr.microsoft.com

@varunsh-coder
Copy link
Member

Hi @jauderho, can you please share a link to a workflow where you observed this? Thanks!

@jauderho
Copy link
Contributor Author

jauderho commented Jan 20, 2023

Interesting, harden-runner does not actually capture the subdomain in the harden-runner output: https://app.stepsecurity.io/github/jauderho/dockerfiles/actions/runs/3965278228

But this can be see in the GHA output: https://github.com/jauderho/dockerfiles/actions/runs/3965278228/jobs/6794861825#step:20:51

This is for a successful run where mcr.microsoft.com resolves to eastus.mcr.microsoft.com

@jauderho
Copy link
Contributor Author

jauderho commented Jan 20, 2023

This is for an unsuccessful run. I just enabled telemetry and set to block.

As you can see from the harden-runner output, only mcr.microsoft.com shows up in the recommended policy for allowed-endpoints but not eastus.data.mcr.microsoft.com.

@sozercan
Copy link

sozercan commented Jan 27, 2023

seeing the same issue after changing egress policy to block while allowlisting mcr.microsoft.com

https://github.com/Azure/eraser/actions/runs/4028112467/jobs/6924673782#step:10:31

@varunsh-coder
Copy link
Member

Thanks for reporting, @sozercan! It looks like MCR decides at runtime what location to pull from.

Investigating this issue is in the backlog and we will get to it soon.

@h0x0er please investigate this next. Thanks!

@h0x0er
Copy link
Member

h0x0er commented Feb 3, 2023

@varunsh-coder, I found that mcr.microsoft.com is used for content-discovery, whereas in order to download image blobs various region specific content-delivery endpoints are used.

The structure of content-delivery endpoints is <region>.data.mcr.microsoft.com. List of regions can be found here.

On executing the below command you will notice; a call to content-discovery endpoints redirects to region specific content-delivery endpoint.

curl https://mcr.microsoft.com/v2/dotnet/aspnet/blobs/sha256:ac9a37082c6dec16dd5bd45d54a08f2e479d37222f2732f5b464e9dd5d454f0a

Ref:

  1. https://github.com/microsoft/containerregistry/blob/main/client-firewall-rules.md
  2. https://github.com/microsoft/containerregistry/blob/main/docs/mcr-endpoints-guidance.md

@varunsh-coder varunsh-coder changed the title Please consider allowlisting *.mcr.microsoft.com Support wildcard domains Apr 14, 2023
@varunsh-coder
Copy link
Member

I have updated the title to a more generic feature - Support wildcard domains.

@varunsh-coder
Copy link
Member

@h0x0er is working on implementing this feature. We plan to release it in two week. I will share rc build to try out in a few days.

@varunsh-coder
Copy link
Member

This feature is now available on the rc tag. Here are a couple of examples. Please try it out and let me know if you have any feedback or questions.

https://github.com/harden-runner-canary/secure-repo-1/blob/166fc181bd964106b97a7dfe5fb13c94b4f20d9d/.github/workflows/release.yml#L23

https://github.com/harden-runner-canary/nvm/blob/72beb77f654e5cdbfa5f259f36eec20f2ca95493/.github/workflows/lint.yml#L32

@varunsh-coder
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants