Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add 'create access token' operation to security events#43226

Merged
vrto merged 6 commits intomainfrom
mv-wd/auditlog/security-events/access-token-created
Oct 24, 2022
Merged

Add 'create access token' operation to security events#43226
vrto merged 6 commits intomainfrom
mv-wd/auditlog/security-events/access-token-created

Conversation

@vrto
Copy link
Contributor

@vrto vrto commented Oct 20, 2022

Description

Expand security events with a new AccessTokenCreated entry and hook it up to the correct place.

Test plan

  • new automated tests
  • manual test at localhost (pair programming session with @willdollman)

@cla-bot cla-bot bot added the cla-signed label Oct 20, 2022
@vrto vrto requested a review from a team October 20, 2022 10:39
securityEventStore := NewDBWith(s.logger, s).SecurityEventLogs()
securityEventStore.LogEvent(ctx, &SecurityEvent{
Name: SecurityEventAccessTokenCreated,
URL: "", // TODO need? - ask in the PR
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sourcegraph/repo-management wasn't sure whether we care about capturing the URL here. Y'all originally added this ~1.5 years ago. Does anyone still remember the original intention behind the URL field?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll let @sourcegraph/repo-management give the definitive answer, but I think this URL only needs to be set if there is an associated URL. Look at the references of .URL.

In this case we don't need it, I think, because the URL doesn't give us anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can't remember to be honest. It looks like it's not populated in that many places in the code and where it is, we just populate the URL path.

https://sourcegraph.sourcegraph.com/github.com/sourcegraph/sourcegraph@09f796bb97fa08e6ebcf2bb9c84aebfe329db29a/-/blob/internal/database/access_tokens.go?L211:4#tab=references

I'm happy to remove it if you're not finding it valuable.

@vrto vrto requested a review from filiphaftek October 20, 2022 10:40
@vrto
Copy link
Contributor Author

vrto commented Oct 20, 2022

@filiphaftek could we use you as a reviewer for the tasks captured in https://github.com/sourcegraph/sourcegraph/issues/37264 or should we tag someone else?

@vrto
Copy link
Contributor Author

vrto commented Oct 20, 2022

@willdollman will follow-up w/ a PR for deletions;

@filiphaftek
Copy link
Contributor

@filiphaftek could we use you as a reviewer for the tasks captured in #37264 or should we tag someone else?

I can do it on Monday, but if you need it faster, maybe @unknwon could have a look? He knows SG code better than me 🙂

_, _, err = db.AccessTokens().CreateInternal(ctx, subject.ID, []string{"a", "b"}, "n0", creator.ID)
assertSecurityEventAccessTokenCreatedCount(t, db, 0)

if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't that check come right after CreateInternal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!


assertSecurityEventAccessTokenCreatedCount(t, db, 0)
tid0, tv0, err := db.AccessTokens().Create(ctx, subject.ID, []string{"a", "b"}, "n0", creator.ID)
assertSecurityEventAccessTokenCreatedCount(t, db, 1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as below. I think you'll need to move that check below.

securityEventStore := NewDBWith(s.logger, s).SecurityEventLogs()
securityEventStore.LogEvent(ctx, &SecurityEvent{
Name: SecurityEventAccessTokenCreated,
URL: "", // TODO need? - ask in the PR
Copy link
Contributor

Choose a reason for hiding this comment

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

I'll let @sourcegraph/repo-management give the definitive answer, but I think this URL only needs to be set if there is an associated URL. Look at the references of .URL.

In this case we don't need it, I think, because the URL doesn't give us anything.

Name: SecurityEventAccessTokenCreated,
URL: "", // TODO need? - ask in the PR
UserID: uint32(creatorUserID),
AnonymousUserID: "",
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to explicitly set default values. Suggest to remove it.

@vrto vrto merged commit 17976a8 into main Oct 24, 2022
@vrto vrto deleted the mv-wd/auditlog/security-events/access-token-created branch October 24, 2022 11:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants