-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add support for storing RDP licenses from Windows Desktops #51250
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
Changes from all commits
e435594
0d182eb
b81b752
1a61dc5
75379f9
fd0ddd7
7c9101f
75262a9
742a516
f1b4122
a85f0ca
a5c1d35
eeb78d1
2b2c329
32dc72b
69862a4
a77b298
ba1567f
d04823e
ab7a5b4
0efab9e
29c1b2c
ab6140a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,9 @@ package storage | |
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/coreos/go-semver/semver" | ||
| "github.com/gravitational/trace" | ||
|
|
@@ -233,6 +235,42 @@ func (p *ProcessStorage) WriteTeleportVersion(ctx context.Context, version *semv | |
| return nil | ||
| } | ||
|
|
||
| func rdpLicenseKey(key *types.RDPLicenseKey) backend.Key { | ||
| return backend.NewKey("rdplicense", key.Issuer, strconv.Itoa(int(key.Version)), key.Company, key.ProductID) | ||
| } | ||
|
|
||
| type rdpLicense struct { | ||
| Data []byte `json:"data"` | ||
| } | ||
|
|
||
| // WriteRDPLicense writes an RDP license to local storage. | ||
| func (p *ProcessStorage) WriteRDPLicense(ctx context.Context, key *types.RDPLicenseKey, license []byte) error { | ||
| value, err := json.Marshal(rdpLicense{Data: license}) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are still working here it's worth checking if key is nil, both in this method and the Read. |
||
| if err != nil { | ||
| return trace.Wrap(err) | ||
| } | ||
| item := backend.Item{ | ||
| Key: rdpLicenseKey(key), | ||
| Value: value, | ||
| Expires: p.BackendStorage.Clock().Now().Add(28 * 24 * time.Hour), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any particular reason behind the 28d expiration? Maybe add a comment?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| _, err = p.stateStorage.Put(ctx, item) | ||
| return trace.Wrap(err) | ||
| } | ||
|
|
||
| // ReadRDPLicense reads a previously obtained license from storage. | ||
| func (p *ProcessStorage) ReadRDPLicense(ctx context.Context, key *types.RDPLicenseKey) ([]byte, error) { | ||
| item, err := p.stateStorage.Get(ctx, rdpLicenseKey(key)) | ||
| if err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
| license := rdpLicense{} | ||
| if err := json.Unmarshal(item.Value, &license); err != nil { | ||
| return nil, trace.Wrap(err) | ||
| } | ||
| return license.Data, nil | ||
| } | ||
|
|
||
|
probakowski marked this conversation as resolved.
|
||
| // ReadLocalIdentity reads, parses and returns the given pub/pri key + cert from the | ||
| // key storage (dataDir). | ||
| func ReadLocalIdentity(dataDir string, id state.IdentityID) (*state.Identity, error) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Teleport | ||
| // Copyright (C) 2025 Gravitational, Inc. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Affero General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Affero General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Affero General Public License | ||
| // along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| package storage | ||
|
|
||
| import ( | ||
| "context" | ||
| "testing" | ||
|
|
||
| "github.com/gravitational/trace" | ||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "github.com/gravitational/teleport/api/types" | ||
| "github.com/gravitational/teleport/lib/backend/memory" | ||
| ) | ||
|
|
||
| func TestRDPLicense(t *testing.T) { | ||
| ctx := context.Background() | ||
| mem, err := memory.New(memory.Config{}) | ||
| require.NoError(t, err) | ||
| storage := ProcessStorage{ | ||
| BackendStorage: mem, | ||
| stateStorage: mem, | ||
| } | ||
|
|
||
| _, err = storage.ReadRDPLicense(ctx, &types.RDPLicenseKey{ | ||
| Version: 1, | ||
| Issuer: "issuer", | ||
| Company: "company", | ||
| ProductID: "productID", | ||
| }) | ||
| require.True(t, trace.IsNotFound(err)) | ||
|
|
||
| licenseData := []byte{1, 2, 3} | ||
| err = storage.WriteRDPLicense(ctx, &types.RDPLicenseKey{ | ||
| Version: 1, | ||
| Issuer: "issuer", | ||
| Company: "company", | ||
| ProductID: "productID", | ||
| }, licenseData) | ||
| require.NoError(t, err) | ||
|
|
||
| _, err = storage.ReadRDPLicense(ctx, &types.RDPLicenseKey{ | ||
| Version: 2, | ||
| Issuer: "issuer", | ||
| Company: "company", | ||
| ProductID: "productID", | ||
| }) | ||
| require.True(t, trace.IsNotFound(err)) | ||
|
|
||
| license, err := storage.ReadRDPLicense(ctx, &types.RDPLicenseKey{ | ||
| Version: 1, | ||
| Issuer: "issuer", | ||
| Company: "company", | ||
| ProductID: "productID", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.Equal(t, licenseData, license) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this type is only used internally then it probably shouldn't exist in the api module.