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

Add revision enforcement #11263

Merged

Conversation

coolo
Copy link
Member

@coolo coolo commented Jun 21, 2021

Continuing on #10992

This is a security flaw in our development flow so we want to have this fixed asap - but the original PR didn't move in the last 2 months.

@hennevogel hennevogel self-requested a review June 21, 2021 09:51
@coolo coolo force-pushed the adrianschroeter-add_revision_enforcement branch from 7142391 to 5ea8792 Compare June 21, 2021 09:53
@adrianschroeter
Copy link
Member

adrianschroeter commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

why not? I added exactly that actually

@codecov
Copy link

codecov bot commented Jun 21, 2021

Codecov Report

Merging #11263 (a054d7e) into master (3f6dd34) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #11263   +/-   ##
=======================================
  Coverage   91.11%   91.11%           
=======================================
  Files         608      608           
  Lines       21890    21893    +3     
=======================================
+ Hits        19944    19947    +3     
  Misses       1946     1946           

@adrianschroeter
Copy link
Member

adrianschroeter commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

I submit revision 2, which points to a _link pointing to a 3rd package - and expect an expanded srcmd5 written in the request

@adrianschroeter
Copy link
Member

adrianschroeter commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

rev=2 is part of the original xml, but not of the one "saved". I guess I don't understand the story. Basically the tpackage being a _link?

@adrianschroeter
Copy link
Member

It is about the source package, we need to verify following situations with the attribute set:

  1. request action xml has no revision specified

  2. request action xml has a revsion specified (no matter if md5sum or number).

2a) Source revision expands to a source without any _link file. We can be sure the source is frozen.
2b) Source revsion expands to a source containing a _link file, means we can not be sure that it is frozen (we do not want to evaluate the _link file content here). So we need to error out, since the user explicit used this revision. (Maybe in good face by suggesting a _link file change, but this is too complex to handle here).

Therefore we need a source server doing the source merging for a proper test case.

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

I mean how can a package expand to a _link? if you can point me to one such case on OBS, I can extend the test.

@adrianschroeter
Copy link
Member

adrianschroeter commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

If you have a devel project, it will contain a link to Factory. If I submit that with revision=HEAD, it will be expanded and the expanded srcmd5 is written into the database. And these expanded sources are what we'll review

@hennevogel
Copy link
Member

@adrianschroeter so can we merge this and you write this test case afterward? You won't change the code right?

@adrianschroeter
Copy link
Member

adrianschroeter commented Jun 21, 2021 via email

@marcus-h
Copy link
Member

marcus-h commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

true, will add an exception for this case

@coolo coolo force-pushed the adrianschroeter-add_revision_enforcement branch from 69d3d6a to 92c8c47 Compare June 21, 2021 17:24
@coolo
Copy link
Member Author

coolo commented Jun 21, 2021

readded the minitest (everyone her hobby :) and added code and test protecting against updatelink

@marcus-h
Copy link
Member

marcus-h commented Jun 21, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 22, 2021

agreed, changed that now

src/api/app/models/bs_request_action.rb Outdated Show resolved Hide resolved
def self.down
AttribType.find_by_namespace_and_name('OBS', 'EnforceRevisionsInRequests').delete
end
end
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 missing changes to db/data_schema.rb, should happen once you run the data migration.

Copy link
Member Author

Choose a reason for hiding this comment

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

hmm, this is a data migration

Copy link
Member

Choose a reason for hiding this comment

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

Yeah and this is data_schema.rb. So if you setup a fresh database for instance, the data migrations are not running afterward.

src/api/spec/models/bs_request_action_spec.rb Outdated Show resolved Hide resolved
@marcus-h
Copy link
Member

marcus-h commented Jun 22, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 23, 2021

That will never be returned as srcmd5 - and we rewrite the source_rev with the expanded srcmd5. So I don't see an issue here.
It's rather an issue for the non-attributed projects, which brings us to the question: why shouldn't this be the default?

adrianschroeter and others added 4 commits June 23, 2021 07:02
Target projects may decide always to get requests with versioned
actions.

Note: revisions to unexpanded sources are still possible!
Once the request is created, we take the given revision, expand
the sources and take the revision given by the backend in the
database. So if any of the components of the submitted sources
is changed afterwards, they don't invalidate reviews
coolo and others added 3 commits June 23, 2021 07:02
Make the comment a little clearer

Co-authored-by: Henne Vogelsang <hvogel@opensuse.org>
For OBS:EnforceRevisionsInRequests projects we want to be certain
what we review is what we accept - and as such we don't want links
to point anywhere, so that updatelink option is incompatible to
that use case
As Marcus pointed out if we skip the check if add_revision
is set, then the user can skip that by setting add_revision,
but having an updatelink option set. As we wouldn't throw
the exception in these cases, it would end up in the database
and potentially only noticed on accept
@coolo coolo force-pushed the adrianschroeter-add_revision_enforcement branch from 8829c59 to a054d7e Compare June 23, 2021 05:09
@marcus-h
Copy link
Member

marcus-h commented Jun 23, 2021 via email

@coolo
Copy link
Member Author

coolo commented Jun 23, 2021

created request id 901414
coolo@nerissa#build-service>osc api /request/901414
<request id="901414" creator="coolo">
  <action type="submit">
    <source project="home:Marcus_H:lnk2" package="b3" rev="upload"/>
    <target project="home:coolo" package="b3"/>
  </action>
  <state name="review" who="coolo" when="2021-06-23T07:05:22">
    <comment/>
  </state>
  <review state="new" when="2021-06-23T07:05:22" by_package="b3" by_project="home:Marcus_H:lnk2"/>
  <description>trying</description>
</request>

This sounds like an even more severe bug - I guess we treat that one in an extra PR.

def self.down
AttribType.find_by_namespace_and_name('OBS', 'EnforceRevisionsInRequests').delete
end
end
Copy link
Member

Choose a reason for hiding this comment

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

Yeah and this is data_schema.rb. So if you setup a fresh database for instance, the data migrations are not running afterward.

@hennevogel hennevogel merged commit 36b8d06 into openSUSE:master Jun 23, 2021
@marcus-h
Copy link
Member

marcus-h commented Jun 24, 2021 via email

@coolo coolo deleted the adrianschroeter-add_revision_enforcement branch June 24, 2021 09:27
@coolo
Copy link
Member Author

coolo commented Jun 24, 2021

I'm all for it - but that's a whole different story, the source revision has no real mapping in the API database. For status API we bind them to repo revisions, but request reviews are an old construct

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.

4 participants