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

[NO-TICKET] Add validation for gem file permissions #3531

Merged
merged 3 commits into from
Mar 18, 2024

Conversation

ivoanjo
Copy link
Member

@ivoanjo ivoanjo commented Mar 18, 2024

What does this PR do?

This PR adds validation so we catch the issue from #3529 before the incorrect packages are published on rubygems.org.

Specifically, it checks that every file in packaged .gem file has the expected permissions.

Motivation:

Avoid #3529 happening again.

Additional Notes:

N/A

How to test the change?

You can run bundle exec rake build to trigger this validation. Try setting incorrect permissions on one of the files and running, and you should see the validation failing.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

**What does this PR do?**

This PR adds validation so we catch the issue from #3529 before the
incorrect packages are published on rubygems.org.

Specifically, it checks that every file in packaged `.gem` file has
the expected permissions.

**Motivation:**

Avoid #3529 happening again.

**Additional Notes:**

N/A

**How to test the change?**

You can run `bundle exec rake build` to trigger this validation. Try
setting incorrect permissions on one of the files and running, and
you should see the validation failing.
@ivoanjo ivoanjo requested a review from a team as a code owner March 18, 2024 14:34
@ivoanjo ivoanjo requested a review from a team March 18, 2024 14:34
require 'rubygems/package/tar_reader'

RSpec.describe 'gem release process (after packaging)' do
# TODO: This will need to be updated for the 2.0 branch
Copy link
Contributor

@AlexJF AlexJF Mar 18, 2024

Choose a reason for hiding this comment

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

Given the release task copies all gems under /pkg maybe we could run this check against all *.gem files in pkg atm? May be slightly annoying in that it may match on things not produced by the build that just ran but any failing files would be invalid gems and should be deleted sooner rather than later anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. I still kept a check that the file we expect is there (just in case we run the spec out-of-order or something like that), but I've expanded it to check every file: b059258

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah keeping the file check is smart indeed!

@TonyCTHsu TonyCTHsu added this to the 1.21.1 milestone Mar 18, 2024
require 'rubygems/package/tar_reader'

RSpec.describe 'gem release process (after packaging)' do
# TODO: This will need to be updated for the 2.0 branch
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah keeping the file check is smart indeed!

This spec only makes sense to run **after** building a gem.
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.24%. Comparing base (6b85e19) to head (37b85eb).
Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3531   +/-   ##
=======================================
  Coverage   98.23%   98.24%           
=======================================
  Files        1275     1275           
  Lines       75303    75303           
  Branches     3558     3558           
=======================================
+ Hits        73977    73978    +1     
+ Misses       1326     1325    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ivoanjo
Copy link
Member Author

ivoanjo commented Mar 18, 2024

I'm going to go ahead and merge this, since the failing CI jobs are unrelated and we're looking into them separately :)

@ivoanjo ivoanjo merged commit ab0601e into master Mar 18, 2024
216 of 219 checks passed
@ivoanjo ivoanjo deleted the ivoanjo/gem-file-permission-validation branch March 18, 2024 17:33
ivoanjo added a commit to DataDog/libdatadog that referenced this pull request Mar 18, 2024
**What does this PR do?**

This PR adds an additional file permission validation step while
building the libdatadog Ruby packages.

This is effectively the same as
DataDog/dd-trace-rb#3531 , and I'm adding it
to avoid the same potential issue.

**Motivation:**

Avoid issue we ran into with `ddtrace` packaging.

**Additional Notes:**

N/A

**How to test the change?**

Running `bundle exec rake package` will trigger the packaging of
the Ruby packages, and you'll see the test running. To see it failing,
`chmod` the `.rb` files to something other than 644.
ivoanjo added a commit that referenced this pull request Mar 19, 2024
**What does this PR do?**

This PR is a follow-up to
#3531: In that PR we added
validation for the permissions of the files in the packaged gem.

After merging that PR, @AlexJF noticed that the GitLab CI `build-gem`
job [was failing with](https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-rb/-/jobs/463401683):

```
Unexpected permissions for CHANGELOG.md inside pkg/ddtrace-1.21.0.dev.bfc613b.glci463401683.g20ea0f3a.gem (got 666, expected 644)
```

These permissions are indeed incorrect and don't match the ones we
expect on actual gem releases.

Thus, I've sprinkled a `chmod` call to fix the permissions before
packaging the gem in gitlab.

You can see in
https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-rb/-/jobs/463581213
that it now works fine:

```
gem release process (after packaging)
  sets the right permissions on the gem files
Finished in 0.07305 seconds (files took 1.2 seconds to load)
```

**Motivation:**

Fix GitLab CI pipeline.

**Additional Notes:**

I guess this check is already flagging permission issues!
Great success :)

**How to test the change?**

See above -- I manually triggered the CI pipeline with this change
and confirmed it passes.
ivoanjo added a commit that referenced this pull request Mar 20, 2024
**What does this PR do?**

This PR is a follow-up to
#3531: In that PR we added
validation for the permissions of the files in the packaged gem.

After merging that PR, @AlexJF noticed that the GitLab CI `build-gem`
job [was failing with](https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-rb/-/jobs/463401683):

```
Unexpected permissions for CHANGELOG.md inside pkg/ddtrace-1.21.0.dev.bfc613b.glci463401683.g20ea0f3a.gem (got 666, expected 644)
```

These permissions are indeed incorrect and don't match the ones we
expect on actual gem releases.

Thus, I've sprinkled a `chmod` call to fix the permissions before
packaging the gem in gitlab.

You can see in
https://gitlab.ddbuild.io/DataDog/apm-reliability/dd-trace-rb/-/jobs/463581213
that it now works fine:

```
gem release process (after packaging)
  sets the right permissions on the gem files
Finished in 0.07305 seconds (files took 1.2 seconds to load)
```

**Motivation:**

Fix GitLab CI pipeline.

**Additional Notes:**

I guess this check is already flagging permission issues!
Great success :)

**How to test the change?**

See above -- I manually triggered the CI pipeline with this change
and confirmed it passes.
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.

6 participants