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

GCE metadata proxy blocks instance identity & recursive calls, & excludes port from redirects #51302

Merged
merged 3 commits into from
Sep 1, 2017

Conversation

ikehz
Copy link
Contributor

@ikehz ikehz commented Aug 25, 2017

What this PR does / why we need it: Metadata proxy blocks instance identity & recursive calls, and no longer includes port in redirects (it was serving redirects to http://metadata.google.internal:988, which doesn't resolve. Ref #8867.

Special notes for your reviewer: Container is defined https://github.com/kubernetes/contrib/tree/master/metadata-proxy; I plan to send a separate PR to remove the nginx.conf directly in the container to reduce confusion.

Release note:

Fix security holes in GCE metadata proxy.

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 25, 2017
@k8s-github-robot k8s-github-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Aug 25, 2017
}

# Allow for REST discovery.
location = / {
if ($args ~ "recursive=true") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tried if recursive=1 or recursive=True or recursive=y etc also effective on GCE metadata server. If it's more permissive than we blacklisted here, it's still a problem.

return 403 "?recursive calls are not allowed by the metadata proxy.";
}
proxy_pass http://169.254.169.254;
}
location = /computeMetadata/ {
if ($args ~ "recursive=true") {
if ($args ~* "recursive") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now afraid this will prevent ?recursive=false, too. @ihmccreery if you've figured out the values that count as true, I think we should add them here. (But then I'll probably worry about if this $args~* check actually normalizes the URLencoding.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel okay about blocking ?recursive=false (and ?recursive=0, etc.), since, as far as I can tell, there's no conventions on a strict set for what to accept as booleans. Params are just a bunch of strings that can be interpreted however the server wants.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(From some messing around, true, 1, yes, and y are all accepted.)

Copy link
Contributor Author

@ikehz ikehz Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(on is also accepted, tried because I found spring-framework's StringToBooleanConverter.java.)

Copy link
Member

@ahmetb ahmetb Aug 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought maybe blocking ?recursive is fine. (We can always relax it later if we get a user request. What I'm actually worried is Google rolling out a software/daemon that runs inside the VM and that makes a ?recursive= query to the metadata server, that sounds apocalyptic.)

I'm not familiar with the nginx.conf language enough to see if it warrants a pattern like ^recursive= (maybe at least leave the = in for more precise matching).

@ikehz ikehz changed the title GCE metadata proxy block instance identity & recursive calls GCE metadata proxy blocks instance identity & recursive calls Aug 30, 2017
@ikehz ikehz changed the title GCE metadata proxy blocks instance identity & recursive calls GCE metadata proxy blocks instance identity & recursive calls, & excludes port from redirects Aug 30, 2017
@ikehz
Copy link
Contributor Author

ikehz commented Aug 30, 2017

@ahmetb I made the regex's a bit more explicit, at your suggestion. If this looks good to you, can I get an lgtm?

Ping @mikedanese @Q-Lee for review?

@ahmetb
Copy link
Member

ahmetb commented Aug 30, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 30, 2017
@ikehz
Copy link
Contributor Author

ikehz commented Aug 30, 2017

/assign @mikedanese

@mikedanese
Copy link
Member

/approve

@k8s-github-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahmetb, ihmccreery, mikedanese

Associated issue: 8867

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 30, 2017
}

# Allow for REST discovery.
location = / {
if ($args ~* "^(.+&)?recursive=") {
return 403 "?recursive calls are not allowed by the metadata proxy.";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should mention the SECURE setting in all of these errors so people realise they are getting this error from the proxy rather than the metadata server itself, and know what to change if they need it to work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't GKE-specific, so we can't mention the GKE feature. The error message needs to also apply to GCE (hence 'metadata proxy').

@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 51628, 51637, 51490, 51279, 51302)

@k8s-github-robot k8s-github-robot merged commit 61bc3aa into kubernetes:master Sep 1, 2017
@wojtek-t wojtek-t added this to the v1.7 milestone Sep 12, 2017
@wojtek-t wojtek-t added cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cherrypick-candidate release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Sep 12, 2017
@wojtek-t wojtek-t removed the release-note-none Denotes a PR that doesn't merit a release note. label Sep 12, 2017
k8s-github-robot pushed a commit that referenced this pull request Sep 12, 2017
…1302-upstream-release-1.7

Automatic merge from submit-queue

Automated cherry pick of #51302

Cherry pick of #51302 on release-1.7.

#51302: Block instance identity, block recursive=true
@k8s-cherrypick-bot
Copy link

Commit found in the "release-1.7" branch appears to be this PR. Removing the "cherrypick-candidate" label. If this is an error find help to get your PR picked.

k8s-github-robot pushed a commit to kubernetes-retired/contrib that referenced this pull request Sep 14, 2017
Automatic merge from submit-queue

Add a container & job spec to check metadata concealment correctness

This checks for some of the fixes made in kubernetes/kubernetes#51302.  Ref #8867.

I'm unsure of where this should live, but this seems like as good a place as any?  @spxtr We discussed, and I'd rather just check it in here now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cherry-pick-approved Indicates a cherry-pick PR into a release branch has been approved by the release branch manager. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants