Skip to content
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

Federated credentials #1094

Merged
merged 155 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 152 commits
Commits
Show all changes
155 commits
Select commit Hold shift + click to select a range
31e49ae
use private containerhelper
freddydk May 30, 2024
9370362
add clientAssertion
freddydk May 31, 2024
2aea50f
dumps
freddydk May 31, 2024
dc3dbc7
not
freddydk May 31, 2024
d3ef5cb
psc
freddydk May 31, 2024
db1c9c3
use iwr
freddydk May 31, 2024
5900990
json
freddydk May 31, 2024
d1bf01c
irm
freddydk May 31, 2024
423f689
dump
freddydk May 31, 2024
5d47747
d
freddydk May 31, 2024
30dc671
irm
freddydk May 31, 2024
1ac4206
url
freddydk May 31, 2024
ca0e591
dump
freddydk May 31, 2024
50a4401
perm
freddydk May 31, 2024
1239fd1
perm
freddydk May 31, 2024
65b70e6
support federated credentials for all
freddydk Jun 1, 2024
4fa155e
dump
freddydk Jun 1, 2024
520c2f5
more dumps
freddydk Jun 1, 2024
cb882ee
dumps
freddydk Jun 1, 2024
b761b20
win
freddydk Jun 1, 2024
0c4982c
remove dumps
freddydk Jun 1, 2024
1711931
version
freddydk Jun 1, 2024
7b6dd87
dump path
freddydk Jun 1, 2024
fccef0d
always install
freddydk Jun 1, 2024
ed6aea5
try
freddydk Jun 1, 2024
748c326
remove
freddydk Jun 1, 2024
6717c40
import
freddydk Jun 1, 2024
ce8dbe2
fed
freddydk Jun 3, 2024
b1dc58e
syntax
freddydk Jun 3, 2024
24fde86
syntax
freddydk Jun 3, 2024
baf3270
add id token permission
freddydk Jun 3, 2024
56c13dd
dump
freddydk Jun 3, 2024
c6c265d
dump
freddydk Jun 3, 2024
2264351
dump b
freddydk Jun 3, 2024
92a8930
dump
freddydk Jun 3, 2024
6215a19
dump secret names
freddydk Jun 3, 2024
96d19b2
dump
freddydk Jun 3, 2024
94b9ffb
no sub
freddydk Jun 3, 2024
b836db5
remove try
freddydk Jun 3, 2024
b289673
sub
freddydk Jun 3, 2024
a198e79
remove dumps
freddydk Jun 3, 2024
7ca44c5
syntax
freddydk Jun 3, 2024
e45b1d4
preview
freddydk Jun 3, 2024
fa77448
outnull
freddydk Jun 3, 2024
1ae6879
no versiontable
freddydk Jun 3, 2024
be7cad6
no sub
freddydk Jun 3, 2024
9cfe7d9
sub
freddydk Jun 3, 2024
1b8c181
install module
freddydk Jun 3, 2024
47336e0
syntax
freddydk Jun 3, 2024
b609b30
add erroraction
freddydk Jun 4, 2024
ae231c6
add idtoken
freddydk Jun 4, 2024
f16b17c
warning is default
freddydk Jun 4, 2024
93b5d80
callstack
freddydk Jun 4, 2024
a5cd65e
dump keys
freddydk Jun 4, 2024
877688b
move to al-go-helper
freddydk Jun 4, 2024
ca6122a
check clientSecret
freddydk Jun 4, 2024
ff71d9d
check not empty
freddydk Jun 4, 2024
0afab8c
replace
freddydk Jun 5, 2024
6e64d6f
ln
freddydk Jun 5, 2024
c3ddb78
sac
freddydk Jun 5, 2024
1a5db97
keys
freddydk Jun 5, 2024
06aabcd
bugs
freddydk Jun 5, 2024
3454902
remove
freddydk Jun 5, 2024
c5ae5df
move
freddydk Jun 5, 2024
ccecaa5
dump
freddydk Jun 5, 2024
3435a61
clientSecret
freddydk Jun 5, 2024
43d54b7
remove dump
freddydk Jun 5, 2024
8e93b73
clientsecret is secret
freddydk Jun 5, 2024
6536189
dumps
freddydk Jun 5, 2024
881a352
non-sec
freddydk Jun 5, 2024
8d46dd3
use azurecreds
freddydk Jun 5, 2024
6d94bc3
dump
freddydk Jun 5, 2024
1f6d4e9
dump keys
freddydk Jun 5, 2024
6139924
dump
freddydk Jun 5, 2024
036ecad
check refresh
freddydk Jun 5, 2024
317b853
remove dumps
freddydk Jun 6, 2024
376b058
Merge branch 'main' into issue1093
freddydk Jun 6, 2024
d14a6b1
Merge branch 'main' into issue1093
freddydk Jun 6, 2024
94c56b2
Update Actions/Sign/Sign.psm1
freddydk Jun 6, 2024
99148c9
Update Actions/Sign/Sign.psm1
freddydk Jun 6, 2024
009c877
code review
freddydk Jun 6, 2024
2eaf829
Delete CODEOWNERS
freddydk Jun 7, 2024
813277b
Create CODEOWNERS
freddydk Jun 7, 2024
dea7304
Update secrets.md
freddydk Jun 7, 2024
c48ce3b
test
freddydk Jun 7, 2024
1a0ee59
update
freddydk Jun 7, 2024
441a5b1
updates
freddydk Jun 7, 2024
e14fb07
release notes
freddydk Jun 7, 2024
5f516ae
update codesigning
freddydk Jun 7, 2024
4fdf8a9
always transfer clientid and tenant
freddydk Jun 9, 2024
a8760f2
not plus
freddydk Jun 9, 2024
2451e07
dump
freddydk Jun 9, 2024
d71224a
remove dump
freddydk Jun 9, 2024
6591c56
add end 2 end for federated credentials
freddydk Jun 10, 2024
b1afa4d
script analyzer
freddydk Jun 10, 2024
2f4e7ee
use var
freddydk Jun 10, 2024
007a419
space
freddydk Jun 10, 2024
049d8b5
Add ClientAssertion check on deploy
freddydk Jun 17, 2024
b737a6b
review
freddydk Jun 17, 2024
9e7125b
check app signature
freddydk Jun 17, 2024
5c2fa49
add repo
freddydk Jun 17, 2024
0f84a60
use windows runner
freddydk Jun 17, 2024
c158a7f
typo
freddydk Jun 17, 2024
d5eb09a
download containerhelper
freddydk Jun 17, 2024
d0f6992
remove tempfolder
freddydk Jun 17, 2024
14bc94c
move containerhelper import
freddydk Jun 17, 2024
cc92a1c
import
freddydk Jun 17, 2024
a0076d7
dotdot
freddydk Jun 17, 2024
ef5d179
add vcredist
freddydk Jun 17, 2024
212f4f1
test
freddydk Jun 17, 2024
1c5b973
process
freddydk Jun 17, 2024
9bca60e
arr
freddydk Jun 17, 2024
3991f35
install both
freddydk Jun 18, 2024
6821ca5
check signing - not whether cert is valid
freddydk Jun 18, 2024
fd3d03d
check no
freddydk Jun 18, 2024
c7cba54
use ascii
freddydk Jun 18, 2024
f55b984
Merge branch 'main' into issue1093
freddydk Jun 18, 2024
ddb7982
Merge branch 'main' into issue1093
freddydk Jun 21, 2024
b3aae56
review
freddydk Jun 22, 2024
4e2e408
Add az modules to packages.json
freddydk Jun 23, 2024
4f909ec
include clouddevenv
freddydk Jun 23, 2024
4e6c397
add idtoken
freddydk Jun 23, 2024
10bfc24
remove erroraction functionality from deliver
freddydk Jun 23, 2024
e14c443
Merge branch 'main' into issue1093
freddydk Jun 23, 2024
0e0f1c8
Update Actions/AL-Go-Helper.ps1
freddydk Jun 24, 2024
315df28
review
freddydk Jun 24, 2024
873189a
Merge branch 'issue1093' of https://github.com/freddydk/AL-Go into is…
freddydk Jun 24, 2024
500c16f
Merge branch 'main' into issue1093
freddydk Jun 24, 2024
66e2d85
Merge branch 'main' into issue1093
freddydk Jun 24, 2024
bb43c77
pre-commit
freddydk Jun 24, 2024
0b049f1
Revert "pre-commit"
freddydk Jun 24, 2024
fe7d558
keep line endings
freddydk Jun 24, 2024
efbc2e5
pre-commit
freddydk Jun 24, 2024
8af178f
remove erroraction
freddydk Jun 24, 2024
df85a08
Merge branch 'main' into issue1093
freddydk Jun 24, 2024
4101d44
Test failure
freddydk Jun 24, 2024
6fafcbd
Merge branch 'issue1093' of https://github.com/freddydk/AL-Go into is…
freddydk Jun 24, 2024
51b7038
Update Actions/AL-Go-Helper.ps1
freddydk Jun 25, 2024
52c4e6c
review
freddydk Jun 25, 2024
0a7e701
Merge branch 'issue1093' of https://github.com/freddydk/AL-Go into is…
freddydk Jun 25, 2024
d62c481
review
freddydk Jun 25, 2024
5b92af2
Update Scenarios/secrets.md
freddydk Jun 25, 2024
ea9e7ab
Update Scenarios/secrets.md
freddydk Jun 25, 2024
a9779a8
Update Scenarios/secrets.md
freddydk Jun 25, 2024
d190e50
Update Scenarios/Codesigning.md
freddydk Jun 25, 2024
978b848
Update Scenarios/secrets.md
freddydk Jun 25, 2024
3ee4c40
Update Scenarios/secrets.md
freddydk Jun 25, 2024
cb71eb9
Update Scenarios/secrets.md
freddydk Jun 25, 2024
0d8b017
Update Scenarios/secrets.md
freddydk Jun 25, 2024
7a1c93d
review
freddydk Jun 25, 2024
508df49
review
freddydk Jun 25, 2024
0a9392a
pre-commit
freddydk Jun 25, 2024
0dc2016
add release note
freddydk Jun 25, 2024
77bbb15
Merge branch 'main' into issue1093
freddydk Jun 25, 2024
8da8b79
Update RELEASENOTES.md
freddydk Jun 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/E2E.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
Write-Host "scenarios=$scenariosJson"

Scenario:
runs-on: [ ubuntu-latest ]
runs-on: [ windows-latest ]
needs: [ Check, SetupRepositories, Analyze ]
if: github.event.inputs.runScenarios == 'true'
strategy: ${{ fromJson(needs.Analyze.outputs.scenarios) }}
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
rev: 0.7.17
hooks:
- id: mdformat
args: [--end-of-line=crlf]
args: [--end-of-line=keep]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
Expand Down
100 changes: 85 additions & 15 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1269,21 +1269,25 @@ function GetProjectFolders {
$projectFolders
}

function installModules {
function InstallModule {
Param(
[String[]] $modules
[String] $name,
[System.Version] $minimumVersion = $null
)

$modules | ForEach-Object {
if (-not (get-installedmodule -Name $_ -ErrorAction SilentlyContinue)) {
Write-Host "Installing module $_"
Install-Module $_ -Force | Out-Null
}
if ($null -eq $minimumVersion) {
$minimumVersion = [System.Version](GetPackageVersion -packageName $name)
}
$module = Get-Module -name $name -ListAvailable | Select-Object -First 1
if ($module -and $module.Version -ge $minimumVersion) {
Write-Host "Module $name is available in version $($module.Version)"
}
$modules | ForEach-Object {
Write-Host "Importing module $_"
Import-Module $_ -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
else {
Write-Host "Installing module $name (minimum version $minimumVersion)"
Install-Module -Name $name -MinimumVersion "$minimumVersion" -Force | Out-Null
}
Write-Host "Importing module $name (minimum version $minimumVersion)"
Import-Module -Name $name -MinimumVersion $minimumVersion -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
}

function CloneIntoNewFolder {
Expand Down Expand Up @@ -1329,7 +1333,7 @@ function CommitFromNewFolder {
Param(
[string] $serverUrl,
[string] $commitMessage,
[string] $body = '',
[string] $body = $commitMessage,
[string] $branch
)

Expand Down Expand Up @@ -1664,7 +1668,7 @@ function CreateDevEnv {

if (($settings.keyVaultName) -and -not ($bcAuthContext)) {
Write-Host "Reading Key Vault $($settings.keyVaultName)"
installModules -modules @('Az.KeyVault')
InstallAzModuleIfNeeded -name 'Az.KeyVault'

if ($kind -eq "local") {
$LicenseFileSecret = Get-AzKeyVaultSecret -VaultName $settings.keyVaultName -Name $settings.licenseFileUrlSecretName
Expand Down Expand Up @@ -2357,14 +2361,80 @@ function GetProjectsFromRepository {
return @(GetMatchingProjects -projects $projects -selectProjects $selectProjects)
}

function Get-PackageVersion($PackageName) {
function GetPackageVersion($packageName) {
$alGoPackages = Get-Content -Path "$PSScriptRoot\Packages.json" | ConvertFrom-Json

# Check if the package is in the list of packages
if ($alGoPackages.PSobject.Properties.name -match $PackageName) {
return $alGoPackages.$PackageName
if ($alGoPackages.PSobject.Properties.name -eq $PackageName) {
return $alGoPackages."$PackageName"
}
else {
throw "Package $PackageName is not in the list of packages"
}
}

function InstallAzModuleIfNeeded {
Param(
[string] $name,
[System.version] $minimumVersion = $null
)

if ($null -eq $minimumVersion) {
$minimumVersion = [System.Version](GetPackageVersion -packageName $name)
}
$azModule = Get-Module -Name $name
if ($azModule -and $azModule.Version -ge $minimumVersion) {
# Already installed
return
}
# GitHub hosted Linux runners have AZ PowerShell module saved in /usr/share/powershell/Modules/Az.*
if ($isWindows) {
# GitHub hosted Windows Runners have AzureRm PowerShell modules installed (deprecated)
# GitHub hosted Windows Runners have AZ PowerShell module saved in C:\Modules\az_*
# Remove AzureRm modules from PSModulePath and add AZ modules
freddydk marked this conversation as resolved.
Show resolved Hide resolved
if (Test-Path 'C:\Modules\az_*') {
$azModulesPath = Get-ChildItem 'C:\Modules\az_*' | Where-Object { $_.PSIsContainer }
if ($azModulesPath) {
Write-Host "Adding AZ module path: $($azModulesPath.FullName)"
$ENV:PSModulePath = "$($azModulesPath.FullName);$(("$ENV:PSModulePath".Split(';') | Where-Object { $_ -notlike 'C:\\Modules\Azure*' }) -join ';')"
}
}
}
InstallModule -name $name -minimumVersion $minimumVersion
}

function ConnectAz {
freddydk marked this conversation as resolved.
Show resolved Hide resolved
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Justification = 'GitHub Secrets come in as plain text')]
param(
[PsCustomObject] $azureCredentials
)
try {
Clear-AzContext -Scope Process
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
if ($azureCredentials.PSObject.Properties.Name -eq 'ClientSecret' -and $azureCredentials.ClientSecret) {
Write-Host "Connecting to Azure using clientId and clientSecret."
$credential = New-Object pscredential -ArgumentList $azureCredentials.ClientId, (ConvertTo-SecureString -string $azureCredentials.ClientSecret -AsPlainText -Force)
Connect-AzAccount -ServicePrincipal -Tenant $azureCredentials.TenantId -Credential $credential -WarningAction SilentlyContinue | Out-Null
}
else {
try {
Write-Host "Query federated token"
$result = Invoke-RestMethod -Method GET -UseBasicParsing -Headers @{ "Authorization" = "bearer $ENV:ACTIONS_ID_TOKEN_REQUEST_TOKEN"; "Accept" = "application/vnd.github+json" } -Uri "$ENV:ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange"
}
catch {
throw "Unable to get federated token, maybe id_token: write permissions are missing. Error was $($_.Exception.Message)"
}
Write-Host "Connecting to Azure using clientId and federated token."
Connect-AzAccount -ApplicationId $azureCredentials.ClientId -Tenant $azureCredentials.TenantId -FederatedToken $result.value -WarningAction SilentlyContinue | Out-Null
}
if ($azureCredentials.PSObject.Properties.Name -eq 'SubscriptionId' -and $azureCredentials.SubscriptionId) {
Write-Host "Selecting subscription $($azureCredentials.SubscriptionId)"
Set-AzContext -SubscriptionId $azureCredentials.SubscriptionId -Tenant $azureCredentials.TenantId -ErrorAction SilentlyContinue -WarningAction SilentlyContinue | Out-Null
}
$script:keyvaultConnectionExists = $true
Write-Host "Successfully connected to Azure"
}
catch {
throw "Error trying to authenticate to Azure. Error was $($_.Exception.Message)"
}
}
93 changes: 47 additions & 46 deletions Actions/Deliver/Deliver.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,49 @@
[bool] $goLive
)

$telemetryScope = $null

function EnsureAzStorageModule() {
if (get-command New-AzStorageContext -ErrorAction SilentlyContinue) {
Write-Host "Using Az.Storage PowerShell module"
function ConnectAzStorageAccount {
Param(
[PSCustomObject] $storageAccountCredentials
)

$azStorageContext = $null
if ($storageAccountCredentials.PSObject.Properties.Name -eq 'sastoken') {
try {
Write-Host "Creating AzStorageContext based on StorageAccountName and sastoken"
$azStorageContext = New-AzStorageContext -StorageAccountName $storageAccountCredentials.StorageAccountName -SasToken $storageAccountCredentials.sastoken
}
catch {
throw "Unable to create AzStorageContext based on StorageAccountName and sastoken. Error was: $($_.Exception.Message)"
}
}
else {
$azureStorageModule = Get-Module -name 'Azure.Storage' -ListAvailable | Select-Object -First 1
if ($azureStorageModule) {
Write-Host "Azure.Storage Module is available in version $($azureStorageModule.Version)"
Write-Host "Using Azure.Storage version $($azureStorageModule.Version)"
Import-Module 'Azure.Storage' -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
Set-Alias -Name New-AzStorageContext -Value New-AzureStorageContext -Scope Script
Set-Alias -Name Get-AzStorageContainer -Value Get-AzureStorageContainer -Scope Script
Set-Alias -Name New-AzStorageContainer -Value New-AzureStorageContainer -Scope Script
Set-Alias -Name Set-AzStorageBlobContent -Value Set-AzureStorageBlobContent -Scope Script
elseif ($storageAccountCredentials.PSObject.Properties.Name -eq 'StorageAccountKey') {
try {
Write-Host "Creating AzStorageContext based on StorageAccountName and StorageAccountKey"
$azStorageContext = New-AzStorageContext -StorageAccountName $storageAccountCredentials.StorageAccountName -StorageAccountKey $storageAccountCredentials.StorageAccountKey
}
else {
Write-Host "Installing and importing Az.Storage."
Install-Module 'Az.Storage' -Force
Import-Module 'Az.Storage' -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
catch {
throw "Unable to create AzStorageContext based on StorageAccountName and StorageAccountKey. Error was: $($_.Exception.Message)"
}
}
elseif (($storageAccountCredentials.PSObject.Properties.Name -eq 'clientID') -and ($storageAccountCredentials.PSObject.Properties.Name -eq 'tenantID')) {
try {
InstallAzModuleIfNeeded -name 'Az.Accounts'
ConnectAz -azureCredentials $storageAccountCredentials
Write-Host "Creating AzStorageContext based on StorageAccountName and managed identity/app registration"
$azStorageContext = New-AzStorageContext -StorageAccountName $storageAccountCredentials.StorageAccountName -UseConnectedAccount
}
catch {
throw "Unable to create AzStorageContext based on StorageAccountName and managed identity. Error was: $($_.Exception.Message)"
}
}
else {
throw "Insufficient information in StorageContext secret. See https://aka.ms/algosettings#storagecontext for details"
}
return $azStorageContext
}

$telemetryScope = $null

try {
. (Join-Path -Path $PSScriptRoot -ChildPath "../AL-Go-Helper.ps1" -Resolve)
DownloadAndImportBcContainerHelper
Expand Down Expand Up @@ -315,35 +333,17 @@ try {
Push-BcNuGetPackage -nuGetServerUrl $nuGetServerUrl -nuGetToken $nuGetToken -bcNuGetPackage $package
}
elseif ($deliveryTarget -eq "Storage") {
EnsureAzStorageModule
InstallAzModuleIfNeeded -name 'Az.Storage'
try {
$storageAccount = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.storageContext)) | ConvertFrom-Json | ConvertTo-HashTable
# Check that containerName and blobName are present
$storageAccount.containerName | Out-Null
$storageAccount.blobName | Out-Null
$storageAccountCredentials = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.storageContext)) | ConvertFrom-Json
$storageAccountCredentials.StorageAccountName | Out-Null
freddydk marked this conversation as resolved.
Show resolved Hide resolved
$storageContainerName = $storageAccountCredentials.ContainerName.ToLowerInvariant().replace('{project}',$projectName).replace('{branch}',$refname).ToLowerInvariant()
$storageBlobName = $storageAccountCredentials.BlobName.ToLowerInvariant()
}
catch {
throw "StorageContext secret is malformed. Needs to be formatted as Json, containing StorageAccountName, containerName, blobName and sastoken or storageAccountKey.`nError was: $($_.Exception.Message)"
}
if ($storageAccount.Keys -contains 'sastoken') {
try {
$azStorageContext = New-AzStorageContext -StorageAccountName $storageAccount.StorageAccountName -SasToken $storageAccount.sastoken
}
catch {
throw "Unable to create AzStorageContext based on StorageAccountName and sastoken.`nError was: $($_.Exception.Message)"
}
throw "StorageContext secret is malformed. Needs to be formatted as Json, containing StorageAccountName, containerName, blobName.`nError was: $($_.Exception.Message)"
}
else {
try {
$azStorageContext = New-AzStorageContext -StorageAccountName $storageAccount.StorageAccountName -StorageAccountKey $storageAccount.StorageAccountKey
}
catch {
throw "Unable to create AzStorageContext based on StorageAccountName and StorageAccountKey.`nError was: $($_.Exception.Message)"
}
}

$storageContainerName = $storageAccount.ContainerName.ToLowerInvariant().replace('{project}',$projectName).replace('{branch}',$refname).ToLowerInvariant()
$storageBlobName = $storageAccount.BlobName.ToLowerInvariant()
$azStorageContext = ConnectAzStorageAccount -storageAccountCredentials $storageAccountCredentials
Write-Host "Storage Container Name is $storageContainerName"
Write-Host "Storage Blob Name is $storageBlobName"

Expand All @@ -360,7 +360,7 @@ try {
New-AzStorageContainer -Context $azStorageContext -Name $storageContainerName | Out-Null
}

Write-Host "Delivering to $storageContainerName in $($storageAccount.StorageAccountName)"
Write-Host "Delivering to $storageContainerName in $($storageAccountCredentials.StorageAccountName)"
$atypes.Split(',') | ForEach-Object {
$atype = $_
Write-Host "Looking for: $project-$refname-$atype-*.*.*.*"
Expand Down Expand Up @@ -415,7 +415,8 @@ try {
# if type is Release, we only get here with the projects that needs to be delivered to AppSource
# if type is CD, we get here for all projects, but should only deliver to AppSource if AppSourceContinuousDelivery is set to true
if ($type -eq 'Release' -or $projectSettings.deliverToAppSource.continuousDelivery) {
EnsureAzStorageModule
# AppSource submission requires the Az.Storage module
InstallAzModuleIfNeeded -name 'Az.Storage'
$appSourceContext = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets.appSourceContext)) | ConvertFrom-Json | ConvertTo-HashTable
if (!$appSourceContext) {
throw "appSourceContext secret is missing"
Expand Down
12 changes: 1 addition & 11 deletions Actions/Deploy/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ $deploymentSettings = $deploymentEnvironments."$environmentName"
$envName = $environmentName.Split(' ')[0]
$secrets = $env:Secrets | ConvertFrom-Json

# Check obsolete secrets
"$($envName)-EnvironmentName","$($envName)_EnvironmentName","EnvironmentName" | ForEach-Object {
if ($secrets."$_") {
throw "The secret $_ is obsolete and should be replaced by using the EnvironmentName property in the DeployTo$envName setting in .github/AL-Go-Settings.json instead"
}
}
if ($secrets.Projects) {
throw "The secret Projects is obsolete and should be replaced by using the Projects property in the DeployTo$envName setting in .github/AL-Go-Settings.json instead"
}

$authContext = $null
foreach($secretName in "$($envName)-AuthContext","$($envName)_AuthContext","AuthContext") {
if ($secrets."$secretName") {
Expand Down Expand Up @@ -110,7 +100,7 @@ else {

try {
$sandboxEnvironment = ($response.environmentType -eq 1)
if ($sandboxEnvironment -and !($bcAuthContext.ClientSecret)) {
if ($sandboxEnvironment -and !($bcAuthContext.ClientSecret -or $bcAuthContext.ClientAssertion)) {
# Sandbox and not S2S -> use dev endpoint (Publish-BcContainerApp)
$parameters = @{
"bcAuthContext" = $bcAuthContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
function IncludeBranch([string] $deliveryTarget) {
$settingsName = "DeliverTo$deliveryTarget"
if ($settings.Contains($settingsName) -and $settings."$settingsName".Contains('Branches')) {
Write-Host "- Branches defined: $($settings."$settingsName".Branches -join ', ') - "
Write-Host "- Branches defined: $($settings."$settingsName".Branches -join ', ')"
return ($null -ne ($settings."$settingsName".Branches | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }))
}
else {
Expand All @@ -18,7 +18,7 @@ function IncludeBranch([string] $deliveryTarget) {
}

function IncludeDeliveryTarget([string] $deliveryTarget) {
Write-Host "DeliveryTarget $_ - "
Write-Host "DeliveryTarget $_"
# DeliveryTarget Context Secret needs to be specified for a delivery target to be included
$contextName = "$($_)Context"
$secrets = $env:Secrets | ConvertFrom-Json
Expand All @@ -38,7 +38,7 @@ if ($settings.type -eq "AppSource App") {
($projectsJson | ConvertFrom-Json) | ForEach-Object {
$projectSettings = ReadSettings -project $_
if ($projectSettings.deliverToAppSource.ContinuousDelivery -or ($projectSettings.Contains('AppSourceContinuousDelivery') -and $projectSettings.AppSourceContinuousDelivery)) {
Write-Host "Project $_ is setup for Continuous Delivery"
Write-Host "Project $_ is setup for Continuous Delivery to AppSource"
$deliveryTargets += @("AppSource")
}
}
Expand Down
5 changes: 4 additions & 1 deletion Actions/Packages.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"sign": "0.9.1-beta.24123.2"
"sign": "0.9.1-beta.24123.2",
"Az.Accounts": "2.15.1",
"Az.Storage": "6.1.1",
"Az.KeyVault": "5.2.0"
}
11 changes: 11 additions & 0 deletions Actions/ReadSecrets/ReadSecrets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ try {
MaskValue -key "$($secretName).$($keyName)" -value "$($json."$keyName")"
}
}
if ($json.ContainsKey('clientID') -and !($json.ContainsKey('clientSecret') -or $json.ContainsKey('refreshToken'))) {
try {
Write-Host "Query federated token"
$result = Invoke-RestMethod -Method GET -UseBasicParsing -Headers @{ "Authorization" = "bearer $ENV:ACTIONS_ID_TOKEN_REQUEST_TOKEN"; "Accept" = "application/vnd.github+json" } -Uri "$ENV:ACTIONS_ID_TOKEN_REQUEST_URL&audience=api://AzureADTokenExchange"
$json += @{ "clientAssertion" = $result.value }
$secretValue = $json | ConvertTo-Json -Compress
}
catch {
throw "$SecretName doesn't contain any ClientSecret and AL-Go is unable to acquire an ID_TOKEN. Error was $($_.Exception.Message)"
}
}
}
$base64value = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($secretValue))
$outSecrets += @{ "$secretsProperty" = $base64value }
Expand Down
Loading
Loading