-
Notifications
You must be signed in to change notification settings - Fork 62
[Feature] Enable get-token and bootstrap certificate from Key Vault #613
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
Open
nchapagain001
wants to merge
29
commits into
main
Choose a base branch
from
users/nchapagain/Feature_Enable_KV_AccessToken
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
acfbbbe
Adding token
nchapagain001 ffd7423
Adding UT for AccessToken.
nchapagain001 cc08bf0
Clean up
nchapagain001 63af6a1
Idea for endpoint parsing.
nchapagain001 910b9c9
saving existing work
f113108
get-token works with tenantId praameter and tid from key vault uri
c4c452c
Foo
4121ce8
Working version
14c5f57
foo
f56c485
minor fix
c73e3cb
added get-token and install-cert as two seperate commands.
98b6a45
Adding UT
abfb780
Merge branch 'main' into users/nchapagain/Feature_Enable_KV_AccessToken
nchapagain001 e31317b
FixUT1
3390b14
minor changes
a64b83a
Including everything in bootstrap
e668337
combined with bootstrap
c940871
Adding doc and UTs.
5a77651
Fixing doc
7483aeb
bumping version
9095fcc
Update src/VirtualClient/VirtualClient.Dependencies/CertificateInstal…
nchapagain001 de5a99f
Update src/VirtualClient/VirtualClient.Main/InstallCertCommand.cs
nchapagain001 1bd7cc0
Update src/VirtualClient/VirtualClient.Main/BootstrapPackageCommand.cs
nchapagain001 7bb5ccb
Update src/VirtualClient/VirtualClient.Core/Identity/AccessTokenCrede…
nchapagain001 358d1c2
[WIP] Update changes from feedback on Key Vault integration (#638)
Copilot 18fd6cd
[WIP] Address feedback on enabling get-token and bootstrap certificat…
Copilot e54ecff
Clarify tenant ID requirement in get-token documentation (#640)
Copilot 8c78582
copilot suggestions
0793d4d
copilot suggestion
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 2.1.55 | ||
| 2.1.56 |
63 changes: 63 additions & 0 deletions
63
src/VirtualClient/VirtualClient.Actions.FunctionalTests/GetAccessTokenProfileTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace VirtualClient.Actions | ||
| { | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Moq; | ||
| using NUnit.Framework; | ||
| using VirtualClient.Common; | ||
| using VirtualClient.Contracts; | ||
|
|
||
| [TestFixture] | ||
| [Category("Functional")] | ||
| public class GetAccessTokenProfileTests | ||
| { | ||
| private DependencyFixture dependencyFixture; | ||
|
|
||
| [OneTimeSetUp] | ||
| public void SetupFixture() | ||
| { | ||
| this.dependencyFixture = new DependencyFixture(); | ||
| ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory); | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("GET-ACCESS-TOKEN.json", PlatformID.Unix)] | ||
| [TestCase("GET-ACCESS-TOKEN.json", PlatformID.Win32NT)] | ||
| public void GetAccessTokenProfileParametersAreInlinedCorrectly(string profile, PlatformID platform) | ||
| { | ||
| this.dependencyFixture.Setup(platform); | ||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.dependencyFixture.Dependencies)) | ||
| { | ||
| WorkloadAssert.ParameterReferencesInlined(executor.Profile); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [TestCase("GET-ACCESS-TOKEN.json", PlatformID.Unix)] | ||
| [TestCase("GET-ACCESS-TOKEN.json", PlatformID.Win32NT)] | ||
| public void GetAccessTokenProfileParametersAreAvailable(string profile, PlatformID platform) | ||
| { | ||
| this.dependencyFixture.Setup(platform); | ||
|
|
||
| var mandatoryParameters = new List<string> { "KeyVaultUri", "TenantId" }; | ||
| using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.dependencyFixture.Dependencies)) | ||
| { | ||
| Assert.IsEmpty(executor.Profile.Actions); | ||
| Assert.AreEqual(1, executor.Profile.Dependencies.Count); | ||
|
|
||
| var dependencyBlock = executor.Profile.Dependencies.FirstOrDefault(); | ||
|
|
||
| foreach (var parameters in mandatoryParameters) | ||
| { | ||
| Assert.IsTrue(dependencyBlock.Parameters.ContainsKey(parameters)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/VirtualClient/VirtualClient.Core/Identity/AccessTokenCredential.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| namespace VirtualClient.Identity | ||
| { | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core; | ||
| using VirtualClient.Common.Extensions; | ||
|
|
||
| /// <summary> | ||
| /// A <see cref="TokenCredential"/> implementation that uses a pre-acquired | ||
| /// access token. | ||
| /// </summary> | ||
| public class AccessTokenCredential : TokenCredential | ||
| { | ||
| /// <summary> | ||
| /// Creates a new instance of the <see cref="AccessTokenCredential"/> class. | ||
| /// </summary> | ||
| /// <param name="token"> | ||
| /// The access token string to use for authentication. | ||
| /// </param> | ||
| public AccessTokenCredential(string token) | ||
| { | ||
| token.ThrowIfNull(nameof(token)); | ||
| this.AccessToken = new AccessToken(token, DateTimeOffset.UtcNow.AddHours(1)); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The access token to use for authentication. | ||
| /// </summary> | ||
| public AccessToken AccessToken { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets an access token using the underlying credentials. | ||
| /// </summary> | ||
| /// <param name="requestContext">Context information used when getting the access token.</param> | ||
| /// <param name="cancellationToken">A token that can be used to cancel the operation.</param> | ||
| /// <returns> | ||
| /// An access token that can be used to authenticate with Azure resources. | ||
| /// </returns> | ||
| public override AccessToken GetToken(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
| { | ||
| return this.AccessToken; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets an access token using the underlying credentials. | ||
| /// </summary> | ||
| /// <param name="requestContext">Context information used when getting the access token.</param> | ||
| /// <param name="cancellationToken">A token that can be used to cancel the operation.</param> | ||
| /// <returns> | ||
| /// An access token that can be used to authenticate with Azure resources. | ||
| /// </returns> | ||
| public override ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
| { | ||
| return new ValueTask<AccessToken>(this.AccessToken); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.