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

test: add test case for setcap in Dockerfile #2082

Conversation

zhouhaibing089
Copy link
Contributor

Description

This is a followup of #1994. This test runs a Dockerfile where setcap is
executed. Without the fix in #1994, the last command won't generate any
diff and thus is discarded by kaniko, and thus should fail this test.

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes unit tests
  • Adds integration tests if needed.

See the contribution guide for more details.

Reviewer Notes

  • The code flow looks good.
  • Unit tests and or integration tests added.

Release Notes

NONE

@zhouhaibing089 zhouhaibing089 force-pushed the add-setcap-test branch 3 times, most recently from 9efdff0 to ce042f0 Compare May 9, 2022 04:59
@@ -893,7 +902,7 @@ func meetsRequirements() bool {
func containerDiff(t *testing.T, image1, image2 string, flags ...string) []byte {
flags = append([]string{"diff"}, flags...)
flags = append(flags, image1, image2,
"-q", "--type=file", "--type=metadata", "--json")
"-q", "--type=file", "--type=metadata", "--history", "--json")
Copy link
Contributor Author

@zhouhaibing089 zhouhaibing089 May 9, 2022

Choose a reason for hiding this comment

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

I guess neither of --type=file and --type=metadata will capture the setcap situation. --history should be able to because the number of image layers should be different if setcap change is discarded.

This is a followup of GoogleContainerTools#1994. This test runs a Dockerfile where setcap is
executed. Without the fix in GoogleContainerTools#1994, the last command won't generate any
diff and thus is discarded by kaniko and thus should fail this test.
Copy link
Collaborator

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

I'm having trouble understanding what the changes to integration_test.go accomplish. It looks like it just additionally tests that the image history is unchanged; is that what we expect in this case?

# See the License for the specific language governing permissions and
# limitations under the License.

FROM wildwildangel/setcap-static:sha-a5c7425
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there another more standard image that we can use to set capabilities in this way? Running this in our tests means we'll depend on wildwildangel not to remove or change this image in ways that may break the test, or worse, inject vulnerabilities into our pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The one above is the closest one I can find.. Other common images would require things like apt-get install libcap2-bin(in debian) - I can update this to debian and add this command, is that a better approach to go?

Copy link
Contributor

@gabyx gabyx May 31, 2022

Choose a reason for hiding this comment

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

I agree here with @imjasonh. There is a TestsLayers test in integration_test https://github.com/GoogleContainerTools/kaniko/blob/main/integration/integration_test.go#L495 which should capture the difference in layer count. Shouldn't that be enough?
This test runs all docker files in integration/dockerfiles.

@zhouhaibing089
Copy link
Contributor Author

It looks like it just additionally tests that the image history is unchanged; is that what we expect in this case?

Yeah, that is what I expect. When kaniko doesn't detect extended attributes like security.capability, the whole layer is discarded and thus it won't appear in image history (I assume). By doing history comparison, we can make sure kaniko doesn't discard such layers.

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 this pull request may close these issues.

3 participants