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

Enable selinux tags in make targets #87658

Merged

Conversation

dims
Copy link
Member

@dims dims commented Jan 29, 2020

In 24d1059, a fix was made in bazel
based builds to ensure that we add selinux tag when we build all
binaries especially the kubelet. We need to do the same for in our
hack scripts so things like make release will work properly as well.

What type of PR is this?
/kind bug

What this PR does / why we need it:

Which issue(s) this PR fixes:

Fixes kubernetes/release#1037

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 29, 2020

/sig release
/sig testing

@k8s-ci-robot k8s-ci-robot added sig/release Categorizes an issue or PR as relevant to SIG Release. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 29, 2020

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 29, 2020

/assign @cblecker @liggitt

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 29, 2020

/hold

for reviews

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 29, 2020
@cblecker
Copy link
Member

Seems fine to me.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 29, 2020

/test pull-kubernetes-e2e-kind
/test pull-kubernetes-e2e-kind-ipv6
/test pull-kubernetes-e2e-gce-device-plugin-gpu

@BenTheElder
Copy link
Member

How do I add another tag for providerless then?
What about typecheck?

@liggitt
Copy link
Member

liggitt commented Jan 29, 2020

How do I add another tag for providerless then?
What about typecheck?

I wondered the same thing

@dims
Copy link
Member Author

dims commented Jan 29, 2020

@BenTheElder we could do GOTAGS similar to the other variables (and append selinux at the end) in a follow up PR.

@dims
Copy link
Member Author

dims commented Jan 29, 2020

/retest

@dims
Copy link
Member Author

dims commented Jan 29, 2020

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 29, 2020
@dims
Copy link
Member Author

dims commented Jan 30, 2020

/test pull-kubernetes-e2e-gce-100-performance

1 similar comment
@dims
Copy link
Member Author

dims commented Jan 31, 2020

/test pull-kubernetes-e2e-gce-100-performance

@dims
Copy link
Member Author

dims commented Jan 31, 2020

/assign @BenTheElder

@@ -785,6 +788,18 @@ kube::golang::build_binaries() {
goasmflags="-trimpath=${KUBE_ROOT}"
gogcflags="${GOGCFLAGS:-} -trimpath=${KUBE_ROOT}"

# extract tags if any specified in GOFLAGS
# shellcheck disable=SC2001
gotags=$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')
Copy link
Member

@BenTheElder BenTheElder Jan 31, 2020

Choose a reason for hiding this comment

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

I think this doesn't work correctly for multiple tags.
If I want to set multiple tags via GOFLAGS to go I have to use:
export GOFLAGS='-tags=selinux -tags=providerless'

this command will give me:

echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|'
providerless

EDIT: potential fix

Suggested change
gotags=$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')
gotags=$(echo "${GOFLAGS:-}" | grep -oe '-tags=\([^- ]*\)' | tr '\n' ' ' | sed -e 's|-tags=\([^-]*\)|\1|g')

Copy link
Member

Choose a reason for hiding this comment

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

something like the above edit, I'm sure it can be done more cleanly ... 🤔

Copy link
Member

@BenTheElder BenTheElder Jan 31, 2020

Choose a reason for hiding this comment

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

Thankfully GOFLAGS specifically expects a space separated set of -flag=value so there may not be too many other edge cases ...

GOFLAGS

	A space-separated list of -flag=value settings to apply
	to go commands by default, when the given flag is known by
	the current command. Each entry must be a standalone flag.
	Because the entries are space-separated, flag values must
	not contain spaces. Flags listed on the command line
	are applied after this list and therefore override it.

https://golang.org/cmd/go/#hdr-Environment_variables

I am not sure if we even need the quote stripping.

Copy link
Member Author

Choose a reason for hiding this comment

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

@BenTheElder from what i understood -tags=selinux -tags=providerless the last one is picked up. So if you do this today selinux would not kick in.

So the test cases i had were as follows (quoting from memory):

  • -tags=providerless
  • -tags='providerless'
  • -tags="providerless"
  • -abc -tags=providerless
  • -abc -tags="providerless"
  • -abc -tags='providerless'
  • -abc -tags=providerless -xyz
  • -abc -tags="providerless" -xyz
  • -abc -tags='providerless' -xyz
  • -abc -tags="providerless selinux" -xyz
  • -abc -tags='providerless selinux' -xyz

Copy link
Member

Choose a reason for hiding this comment

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

So GOFLAGS cannot contain quoted values and the value in -flag=value cannot contain a space.

This means this flag couldn't have more than one value:
golang/go#26849

Except in go1.13 it may be comma seperated for cmd/go
golang/go@80e7832

Need to do some tests when I get to a machine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack. please let me know. Let's wrap this up with spaces first please as the first iteration. i can follow up with support for comma.

Copy link
Member

Choose a reason for hiding this comment

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

[bentheelder@bentheelder:~/junk·2020-01-31T12:31:41-0800]
$ GOFLAGS='-tags=providerless,selinux' go build .

[bentheelder@bentheelder:~/junk·2020-01-31T12:31:48-0800]
$ cat ./a.go
// +build providerless,selinux

package main

func main() {
	println("test")
}

Copy link
Member

Choose a reason for hiding this comment

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

versus:

[bentheelder@bentheelder:~/junk·2020-01-31T12:32:03-0800]
$ GOFLAGS='-tags="providerless selinux"' go build .
go: parsing $GOFLAGS: non-flag "selinux\""

Copy link
Member

@BenTheElder BenTheElder Jan 31, 2020

Choose a reason for hiding this comment

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

we can replace all of this processing with just:

gotags="selinux,$(echo "${GOFLAGS:-}" | sed -e 's|.*-tags=\([^-]*\).*|\1|')"

# strip single quotes
gotags=${gotags//\'}
# trim leading and trailing whitespaces
gotags=$(echo "$gotags" | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }')
Copy link
Member

Choose a reason for hiding this comment

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

leading and trailing whitespace is illegal, as are the quotes, we can drop this and just , join with selinux
requires go 1.13+ but we're on that

# trim leading and trailing whitespaces
gotags=$(echo "$gotags" | awk '{ gsub(/^[ \t]+|[ \t]+$/, ""); print }')
# ensure selinux is specified in the list of tags
gotags="selinux $gotags"
Copy link
Member

Choose a reason for hiding this comment

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

comma instead of a space

Suggested change
gotags="selinux $gotags"
gotags="selinux,${gotags}"

In 24d1059, a fix was made in bazel
based builds to ensure that we add `selinux` tag when we build all
binaries especially the `kubelet`. We need to do the same for in our
hack scripts so things like `make release` will work properly as well.

Some scripts use `GOFLAGS=-tags=providerless` for example, So we should
support the tags to be specified in GOFLAGS as well. We parse out the
tags from there and ensure selinux is added to the list of tags we used
for building the binaries. Note that we add our own `-tags` with the
full set of tags and since we specify our parameter at the end, ours
full list takes precendence
@dims dims force-pushed the enable-selinux-tags-in-make-targets branch from 4072793 to dfd8e4e Compare January 31, 2020 20:49
@BenTheElder
Copy link
Member

/lgtm
/approve
thanks dims!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 31, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: BenTheElder, cblecker, dims

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

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@BenTheElder
Copy link
Member

flake:

[sig-cli] Kubectl client Simple pod should support inline execution and attach expand_more

https://prow.k8s.io/view/gcs/kubernetes-jenkins/pr-logs/pull/87658/pull-kubernetes-e2e-kind/1223347807302193152

cross is super flaky now as well so :/
/retest

@BenTheElder
Copy link
Member

GCE timed out...?
/retest

@dims
Copy link
Member Author

dims commented Feb 1, 2020

/retest

@fejta-bot
Copy link

/retest
This bot automatically retries jobs that failed/flaked on approved PRs (send feedback to fejta).

Review the full test history for this PR.

Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

@simonswine
Copy link
Contributor

@kubernetes/patch-release-team I think this should ideally get cherry-picked into 1.16 and 1.17

See PRs #87752 and #87753

@liggitt
Copy link
Member

liggitt commented Feb 5, 2020

is it expected that https://testgrid.k8s.io/google-gce#gci-gce-flaky&sort-by-flakiness=&width=20&include-filter-by-regex=SELinux are still failing? do we have e2e tests that verify this is effective?

@gnufied
Copy link
Member

gnufied commented Feb 6, 2020

@liggitt I think those tests are faulty. They are failing on - https://github.com/kubernetes/kubernetes/blob/master/test/e2e/node/security_context.go#L272 which checks for ability to not read file correctly if MCS label's don't match. It is throwing following error:

 I0206 18:29:40.492] Feb  6 18:29:40.487: INFO: Running '/workspace/kubernetes/platforms/linux/amd64/kubectl exec --namespace=security-context-2598 security-context-6409b558-55a7-4ae8-b57c-e34291c7c723 -c=
       │ test-container -- cat /mounted_volume/TEST'
 872   │ I0206 18:29:41.804] Feb  6 18:29:41.798: INFO: error running kubectl exec to read file: exit status 1
 873   │ I0206 18:29:41.804] stdout=
 874   │ I0206 18:29:41.804] stderr=cat: can't open '/mounted_volume/TEST': No such file or directory
 875   │ I0206 18:29:41.805] command terminated with exit code 1

Which is exactly as it should happen. The code that does check for ability of pod to read/write the file appears to be passing succuessfully.

@gnufied
Copy link
Member

gnufied commented Feb 6, 2020

If we go to a version before @dims fix the test fails in different place:

home/hekumar/goal/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/test/e2e/framework/framework.go:697
  should support volume SELinux relabeling [Flaky] [LinuxOnly] [It]
  /home/hekumar/goal/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/test/e2e/node/security_context.go:136
                                                     
  Feb  6 14:46:29.944: Unexpected error:
      <*exec.ExitError | 0xc00302dbe0>: {                                                                                                                                                                            
          ProcessState: {     
              pid: 3483,                                                                                                                                                                                                           status: 256,                                                                                                                                                                                           
              rusage: {                                                                                                                                                                                              
                  Utime: {Sec: 0, Usec: 108541},                                                                                                                                                                     
                  Stime: {Sec: 0, Usec: 23003},                                                                                                                                                                      
                  Maxrss: 121484,                                                                                                                                                                                    
                  Ixrss: 0,                                                                                                                                                                                          
                  Idrss: 0,                                                                                                                                                                                                            Isrss: 0,                                                                                                                                                                                          
                  Minflt: 4608,                                                                                                                                                                                                        Majflt: 0,                                                                                                                                                                                                           Nswap: 0,                                                                                                                                                                                                            Inblock: 0,                                                                                                                                                                                                          Oublock: 1168,                                                                                                                                                                                                       Msgsnd: 0,                                                                                                                                                                                         
                  Msgrcv: 0,
                  Nsignals: 0,
                  Nvcsw: 1488,       
                  Nivcsw: 56,                                                                             
              },                                                                                                                                                                                                     
          },                                     
          Stderr: nil,                                                                                                                                                                                               
      }                           
      exit status 1                                                                                       
  occurred                                                                                                
                                                                                                          
  /home/hekumar/goal/src/k8s.io/kubernetes/_output/local/go/src/k8s.io/kubernetes/test/e2e/node/security_context.go:220
------------------------------                                                                                                                 

Which means it does not work with plain emptydir

k8s-ci-robot added a commit that referenced this pull request Feb 21, 2020
…7658-upstream-release-1.17

Automated cherry pick of #87658: Enable selinux tags in make targets
k8s-ci-robot added a commit that referenced this pull request Feb 21, 2020
…7658-upstream-release-1.16

Automated cherry pick of #87658: Enable selinux tags in make targets
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. area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/release Categorizes an issue or PR as relevant to SIG Release. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Golang build tags are not used in release assets
8 participants