Skip to content

Commit 1aca14d

Browse files
committed
🐣 Add module, get into proper version control
0 parents  commit 1aca14d

File tree

5 files changed

+500
-0
lines changed

5 files changed

+500
-0
lines changed

ReadMe.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# AWS SSO Programmatic Credentials, Programmatically
2+
When credentials are available via the AWS SSO Identity Center ("IDC"), we can [reasonably] easily get AWS credentials for use with the AWS tools that we know and love (SDKs, CLIs, PowerShell modules, etc.).
3+
4+
Herein is a PowerShell module that simplifies getting accounts, roles, and credentials for some identity (the user).
5+
6+
## What
7+
Simplify the creation of AWS credentials to SSO accounts/roles that an identity is entitled via AWS SSO Identity Center.
8+
9+
## Quick Start
10+
To import this module
11+
1. Save or install the module from the PowerShell Gallery:
12+
```powershell
13+
## save it locally for initial inspection -- safety first!
14+
Find-Module vN.AWSSSO | Save-Module -Path C:\Temp
15+
## ..then inspect code to confirm trustworthiness
16+
17+
## orrr, install straight away, as vNugglets is a reputable publisher
18+
Find-Module vN.AWSSSO | Install-Module
19+
```
20+
1. Profit (see examples in [How](#how) section below)
21+
22+
### And, handy default value for Parameter
23+
To simplify even further the getting of temporary credentials from AWS for accounts/roles, we can make a default value for the `-StartUrl` parameter of `New-VNAWSSSOOIDCTokenViaDeviceCode`:
24+
```powershell
25+
$PSDefaultParameterValues['New-VNAWSSSOOIDCTokenViaDeviceCode:StartUrl'] = "https://mycoolstart.awsapps.com/start/"
26+
```
27+
This then passes the given URL as the value for `-StartUrl` to this cmdlet each time we invoke the cmdlet. And, of course, we could put that default parameter value definition in somewhere like our PowerShell profile so that this default is always in place.
28+
29+
## Why
30+
It is currently a bit more involved than "auth, then get creds for account/role". So, to make most simple the flow of getting such credentials in a natural way (minimal/zero configuration, and with rich objects and normal filtering we all know and love), let's abstract away the intricacies and make things "just work". 👍
31+
32+
## Gist
33+
Super simple pseudo code depiction:
34+
```
35+
new oidc token | get accounts | get roles | get rolecred | do something with rolecred
36+
```
37+
38+
A bit more explicit-, but still pseudo, flow:
39+
```PowerShell
40+
## some pseudo code to describe the flow
41+
## get the SSO OIDC access token that will allow us to do subsequent things (get account info, get account role info, get role cred)
42+
new ssooidc token
43+
## get the accounts to which the OIDC token provides access
44+
get sso account list | Foreach-Object
45+
## get the SSO-related roles to which we are entitled in the given AWS account
46+
get sso account role list |
47+
## filter on <whatveer we like> to get just the account/role info for which to get temp creds
48+
Where-Object rolename matches something | Foreach-Object
49+
## get the temp creds for the given account and role combos
50+
Get-SSORoleCredential
51+
## do something with those creds; for example, save them in the AWS creds location like .NET SDK or CLI "shared-creds" ini file)
52+
| save the AWS credential
53+
54+
## then, profit!
55+
```
56+
## How
57+
A mostly realistic example of getting some credentials.
58+
59+
1. Authenticate in your web browser as the account you want to use for AWS SSO interaction. For example, if Microsoft is the federated identity provider, go to the account management page there (https://myaccount.microsoft.com) and ensure that the desired account is "signed in" in the given web browser
60+
1. Using cmdlets from this module, get and filter some role/account info, generate new temp credentials, and save them:
61+
```PowerShell
62+
## make a new SSO OIDC token
63+
New-VNAWSSSOOIDCTokenViaDeviceCode -StartUrl https://mycoolstart.awsapps.com/start/ -Verbose
64+
## get account/role info, filter, get cred for role, get AWS temp cred
65+
Get-VNAWSSSOAccountAndRoleInfo |
66+
Where-Object accountname -like my-cool-account-* |
67+
Where-Object RoleName -match _myadminrole_ |
68+
New-VNAWSSSORoleTempCredential -Verbose |
69+
## save to the AWS creds file the temp creds for each account/role
70+
Set-AWSCredential -ProfileLocation (Resolve-Path ~\.aws\credentials)
71+
```
72+
73+
And, to see that example as a likely candidate to paste straight into a PowerShell session (one-line format):
74+
```PowerShell
75+
## make a new SSO OIDC token, get account/role info, filter, get cred for role, get AWS temp cred, save to the AWS creds file the temp creds for each account/role
76+
New-VNAWSSSOOIDCTokenViaDeviceCode -StartUrl https://mycoolstart.awsapps.com/start/; Get-VNAWSSSOAccountAndRoleInfo | Where-Object accountname -like my-cool-account-* | Where-Object RoleName -match _myadminrole_ | New-VNAWSSSORoleTempCredential -Verbose | Set-AWSCredential -ProfileLocation (Resolve-Path ~\.aws\credentials)
77+
```
78+
79+
## More Coolness 😎
80+
One of the wonderful things that this approach enables is the programmatic retrieval of accounts and roles to which an identity/user is entitled.
81+
82+
It is in the "get temp creds" example above, but to focus on the, "get all the roles/accounts I _could_ use" use case:
83+
```PowerShell
84+
## get _all_ account/role info for this user identity
85+
Get-VNAWSSSOAccountAndRoleInfo
86+
## *poof*!
87+
88+
## get account/role info, filter like all the other PowerShell filtering we already know and love ❣!
89+
Get-VNAWSSSOAccountAndRoleInfo |
90+
Where-Object accountname -like my-cool-account-* |
91+
Where-Object RoleName -match _myadminrole_
92+
```
93+
94+
## Other
95+
The native AWS cmdlets can make all of this happen. This module is to simplify such things, so we can:
96+
- easily get the accounts and roles to which our identity is entitled
97+
- this enables the natural PowerShell behavior we know and love of, "get some stuff, maybe filter some stuff, then do something with the stuff"
98+
- so, for example, we can now programmatically get all of the accounts/roles to which we are entitled _as objects_, and then do the rest of the "cool" (valuable) stuff for the use case -- audit access, filter which roles to generate creds for, etc
99+
- easily generate role credentials
100+
- this also enables some natural PowerShell behavior: get some creds and do something with them; namely, save in the \<wherever the use case dictates> location
101+
- ...say, by piping the object to something that will store the credential, like `Set-AWSCredential`, and with the flexibility to specify the traditional filesystem shared-credentials file, or in a secure place (.NET SDK store), or wherever
102+
103+
This module provides similar outcomes to the module https://github.com/e0c615c8e4d846ef817cd5063a88716c/AWSSSOHelper, but also focuses on enabling those aforementioned "natural" PowerShell capabilities / experiences / use-cases.

Update-ThisModuleManifest.ps1

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<# .Description
2+
Some code to help automate the updating of the ModuleManifest file (will create it if it does not yet exist, too)
3+
#>
4+
[CmdletBinding(SupportsShouldProcess=$true)]
5+
param(
6+
## Module Version to set
7+
[parameter(Mandatory=$true)][System.Version]$ModuleVersion,
8+
9+
## Recreate the manifest (overwrite with full, fresh copy instead of update?)
10+
[Switch]$Recreate
11+
)
12+
begin {
13+
$strModuleName = "vN.AWSSSO"
14+
$strFilespecForPsd1 = Join-Path ($strModuleFolderFilespec = "$PSScriptRoot\$strModuleName") "${strModuleName}.psd1"
15+
16+
$hshManifestParams = @{
17+
# Confirm = $true
18+
Path = $strFilespecForPsd1
19+
ModuleVersion = $ModuleVersion
20+
Author = "Matt Boren, vNugglets"
21+
Copyright = "MIT License"
22+
Description = "Module with functions for simplifying and making more natural the getting of AWS accounts, roles, and credentials via AWS SSO Identity Center ('IDC') related 'native' cmdlets from AWS-provided PowerShell modules"
23+
## some aliases
24+
# AliasesToExport = Write-Output "blah"
25+
FileList = Write-Output "${strModuleName}.psd1" "${strModuleName}_functions.psm1" "en-US\about_${strModuleName}.help.txt"
26+
FunctionsToExport = Write-Output Get-VNAWSSSOAccountAndRoleInfo New-VNAWSSSOOIDCTokenViaDeviceCode New-VNAWSSSORoleTempCredential
27+
# IconUri = "https://github.com/vNugglets/something"
28+
# LicenseUri = "https://github.com/vNugglets/something"
29+
## scripts (.ps1) that are listed in the NestedModules key are run in the module's session state, not in the caller's session state. To run a script in the caller's session state, list the script file name in the value of the ScriptsToProcess key in the manifest; RegisterArgCompleter apparently needs to be added _after_ function definition .ps1 files are run (via NestedModules) (else, given functions are not defined, and if RegisterArgCompleter is referring to commands from module dynamically, it would not get them; that is the case if the function definitions are in a .psm1 file instead of .ps1 file, and are being defined in NestedModules)
30+
# NestedModules = Write-Output "${strModuleName}_functions.psm1"
31+
# PassThru = $true
32+
PowerShellVersion = [System.Version]"7.0"
33+
ProjectUri = "https://github.com/vNugglets/something"
34+
ReleaseNotes = "See release notes / ReadMe at the project URI"
35+
RootModule = "${strModuleName}_functions.psm1"
36+
# RequiredModules = "Some.Other.Module"
37+
Tags = Write-Output AWS SSO IdentityCenter IDC SSOIDC SingleSignOn Natural FaF
38+
# Verbose = $true
39+
} ## end hashtable
40+
} ## end begin
41+
42+
process {
43+
$bManifestFileAlreadyExists = Test-Path $strFilespecForPsd1
44+
## check that the FileList property holds the names of all of the files in the module directory, relative to the module directory
45+
## the relative names of the files in the module directory (just filename for those in module directory, "subdir\filename.txt" for a file in a subdir, etc.)
46+
$arrRelativeNameOfFilesInModuleDirectory = Get-ChildItem $strModuleFolderFilespec -Recurse | Where-Object {-not $_.PSIsContainer} | ForEach-Object {$_.FullName.Replace($strModuleFolderFilespec, "", [System.StringComparison]::OrdinalIgnoreCase).TrimStart("\")}
47+
if ($arrDiffResults = (Compare-Object -ReferenceObject $hshManifestParams.FileList -DifferenceObject $arrRelativeNameOfFilesInModuleDirectory)) {Write-Error "Uh-oh -- FileList property value for making/updating module manifest and actual files present in module directory do not match. Better check that. The variance:`n$($arrDiffResults | Out-String)"} else {Write-Verbose -Verbose "Hurray, all of the files in the module directory are named in the FileList property to use for the module manifest"}
48+
$strMsgForShouldProcess = "{0} module manifest" -f $(if ((-not $bManifestFileAlreadyExists) -or $Recreate) {"Create"} else {"Update"})
49+
if ($PsCmdlet.ShouldProcess($strFilespecForPsd1, $strMsgForShouldProcess)) {
50+
## do the actual module manifest update
51+
if ((-not $bManifestFileAlreadyExists) -or $Recreate) {Microsoft.PowerShell.Core\New-ModuleManifest @hshManifestParams}
52+
else {PowerShellGet\Update-ModuleManifest @hshManifestParams}
53+
## replace the comment in the resulting module manifest that includes "PSGet_" prefixed to the actual module name with a line without "PSGet_" in it
54+
(Get-Content -Path $strFilespecForPsd1 -Raw).Replace("# Module manifest for module 'PSGet_$strModuleName'", "# Module manifest for module '$strModuleName'") | Set-Content -Path $strFilespecForPsd1
55+
} ## end if
56+
} ## end prcoess
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
TOPIC
2+
about_vN.AWSSSO
3+
4+
SHORT DESCRIPTION
5+
Module encapsulating functions for simplified AWS SSO IDC interactions
6+
7+
LONG DESCRIPTION
8+
A module that provides functions for easily interacting with AWS SSO Identity
9+
Center for account- and role information gathering, and temporary credential
10+
creation.
11+
12+
Based on tidbits from Set-AwsCliSsoCredentials.ps1, from AWS at
13+
https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/update-aws-cli-credentials-from-aws-iam-identity-center-by-using-powershell.html
14+
15+
EXAMPLES
16+
All of the cmdlets in this module have proper comment-based help. Discover
17+
and learn via the standard PowerShell way:
18+
19+
Get-Help -Full <cmdlet-name>
20+
21+
KEYWORDS
22+
AWS
23+
AWS SSO
24+
AWS SSO IDC
25+
AWS SSO Identity Center
26+
vN
27+
vNugglets
28+
FaF
29+
30+
SEE ALSO

vN.AWSSSO/vN.AWSSSO.psd1

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#
2+
# Module manifest for module 'vN.AWSSSO'
3+
#
4+
# Generated by: Matt Boren, vNugglets
5+
#
6+
# Generated on: 9/18/2025
7+
#
8+
9+
@{
10+
11+
# Script module or binary module file associated with this manifest.
12+
RootModule = 'vN.AWSSSO_functions.psm1'
13+
14+
# Version number of this module.
15+
ModuleVersion = '1.4.0'
16+
17+
# Supported PSEditions
18+
# CompatiblePSEditions = @()
19+
20+
# ID used to uniquely identify this module
21+
GUID = '8361b1fa-f543-43be-9101-725fb831dedf'
22+
23+
# Author of this module
24+
Author = 'Matt Boren, vNugglets'
25+
26+
# Company or vendor of this module
27+
CompanyName = 'Unknown'
28+
29+
# Copyright statement for this module
30+
Copyright = 'MIT License'
31+
32+
# Description of the functionality provided by this module
33+
Description = 'Module with functions for simplifying and making more natural the getting of AWS accounts, roles, and credentials via AWS SSO Identity Center (''IDC'') related ''native'' cmdlets from AWS-provided PowerShell modules'
34+
35+
# Minimum version of the PowerShell engine required by this module
36+
PowerShellVersion = '7.0'
37+
38+
# Name of the PowerShell host required by this module
39+
# PowerShellHostName = ''
40+
41+
# Minimum version of the PowerShell host required by this module
42+
# PowerShellHostVersion = ''
43+
44+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45+
# DotNetFrameworkVersion = ''
46+
47+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48+
# ClrVersion = ''
49+
50+
# Processor architecture (None, X86, Amd64) required by this module
51+
# ProcessorArchitecture = ''
52+
53+
# Modules that must be imported into the global environment prior to importing this module
54+
# RequiredModules = @()
55+
56+
# Assemblies that must be loaded prior to importing this module
57+
# RequiredAssemblies = @()
58+
59+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60+
# ScriptsToProcess = @()
61+
62+
# Type files (.ps1xml) to be loaded when importing this module
63+
# TypesToProcess = @()
64+
65+
# Format files (.ps1xml) to be loaded when importing this module
66+
# FormatsToProcess = @()
67+
68+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69+
# NestedModules = @()
70+
71+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72+
FunctionsToExport = 'Get-VNAWSSSOAccountAndRoleInfo',
73+
'New-VNAWSSSOOIDCTokenViaDeviceCode',
74+
'New-VNAWSSSORoleTempCredential'
75+
76+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
77+
CmdletsToExport = '*'
78+
79+
# Variables to export from this module
80+
VariablesToExport = '*'
81+
82+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
83+
AliasesToExport = '*'
84+
85+
# DSC resources to export from this module
86+
# DscResourcesToExport = @()
87+
88+
# List of all modules packaged with this module
89+
# ModuleList = @()
90+
91+
# List of all files packaged with this module
92+
FileList = 'vN.AWSSSO.psd1', 'vN.AWSSSO_functions.psm1',
93+
'en-US\about_vN.AWSSSO.help.txt'
94+
95+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
96+
PrivateData = @{
97+
98+
PSData = @{
99+
100+
# Tags applied to this module. These help with module discovery in online galleries.
101+
Tags = 'AWS','SSO','IdentityCenter','IDC','SSOIDC','SingleSignOn','Natural','FaF'
102+
103+
# A URL to the license for this module.
104+
# LicenseUri = ''
105+
106+
# A URL to the main website for this project.
107+
ProjectUri = 'https://github.com/vNugglets/something'
108+
109+
# A URL to an icon representing this module.
110+
# IconUri = ''
111+
112+
# ReleaseNotes of this module
113+
ReleaseNotes = 'See release notes / ReadMe at the project URI'
114+
115+
# Prerelease string of this module
116+
# Prerelease = ''
117+
118+
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
119+
# RequireLicenseAcceptance = $false
120+
121+
# External dependent modules of this module
122+
# ExternalModuleDependencies = @()
123+
124+
} # End of PSData hashtable
125+
126+
} # End of PrivateData hashtable
127+
128+
# HelpInfo URI of this module
129+
# HelpInfoURI = ''
130+
131+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
132+
# DefaultCommandPrefix = ''
133+
134+
}
135+
136+

0 commit comments

Comments
 (0)