Skip to content

Add machinery to do client-side RDP license caching#47634

Closed
zmb3 wants to merge 1 commit intomasterfrom
zmb3/rdp-license-storage
Closed

Add machinery to do client-side RDP license caching#47634
zmb3 wants to merge 1 commit intomasterfrom
zmb3/rdp-license-storage

Conversation

@zmb3
Copy link
Copy Markdown
Collaborator

@zmb3 zmb3 commented Oct 16, 2024

Expose a Cgo interface for writing licenses to the agent's process storage.

@zmb3 zmb3 added backport/branch/v14 no-changelog Indicates that a PR does not require a changelog entry labels Oct 16, 2024
Comment thread lib/srv/desktop/rdp/rdpclient/client.go Outdated
Comment thread lib/srv/desktop/rdp/rdpclient/client.go Outdated
Comment thread lib/srv/desktop/rdp/rdpclient/client.go Outdated
Comment thread lib/srv/desktop/rdp/rdpclient/client.go Outdated
Comment thread lib/auth/storage/storage.go
Expose a Cgo interface for writing licenses to the agent's process
storage.
@zmb3 zmb3 force-pushed the zmb3/rdp-license-storage branch from e3c5e8a to c992a86 Compare October 16, 2024 18:45
@zmb3 zmb3 marked this pull request as ready for review October 16, 2024 22:04
Comment on lines +826 to +827
case len(license) > 0:
log.InfoContext(context.Background(), "found existing RDP license")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what should happen in case of err == nil && len(license) == 0?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

That's not something I've commonly seen in Go code. It's generally safe to assume that a nil error means we're returning valid data.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So why use additional case here? can we skip it and simply log after switch?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure I follow?

I want to be able to tell from the logs if:

  1. We know there wasn't an existing license.
  2. We know there was an existing license.
  3. We don't know if there was a license or not because we encountered an error.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Right now the switch is not exhaustive, case where err == nil and len(license) == 0 will log nothing.
So, we either don't care about the length (we assume it's >0 when err==nil) and we can skip the length check (by either returning early in case of errors above and logging happy path outside of switch or changing last case to default) or we do care and should log something different in that case

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough, we can change the last case to a default case instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could error upon trying to write an empty license (if that's ever plausible) and treat an empty license as a not found error, too.

For what it's worth we seem to always avoid writing items with a blank value in the backend - nothing bad should happen, but...

}

func (p *ProcessStorage) rdpLicenseKey(majorVersion, minorVersion uint16, issuer, company, productID string) backend.Key {
return backend.NewKey("rdplicense", issuer, strconv.Itoa(int(majorVersion)), strconv.Itoa(int(minorVersion)), company, productID)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we ever going to list the licenses? If so, are we more likely to want to list them by issuer major minor company productid, or some other order?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Order of the keys don't really matter as we don't ever need to list them. The only operation we need to support is "does a license exist for these specific values?"

Comment on lines +748 to +758
*data_out = nil
*len_out = 0

client, err := toClient(handle)
if err != nil {
return C.ErrCodeFailure
}

issuer := C.GoString(req.issuer)
company := C.GoString(req.company)
productID := C.GoString(req.product_id)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are currently recovering against panics in toClient; while that's pretty gross, should we be consistent and also check that req and the out pointers are not nil?

Comment on lines +826 to +827
case len(license) > 0:
log.InfoContext(context.Background(), "found existing RDP license")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We could error upon trying to write an empty license (if that's ever plausible) and treat an empty license as a not found error, too.

For what it's worth we seem to always avoid writing items with a blank value in the backend - nothing bad should happen, but...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/branch/v17 desktop-access no-changelog Indicates that a PR does not require a changelog entry rdp size/md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants