Skip to content

Commit baf2bff

Browse files
hashtagnullavn0804VargaJoe
authored
Make sensenet - snauth compatible with docker containerization (#2205)
* Raise internal versions. * modified sn auth authority url to be compatible with docker containers * consolidate docker network to projects * settings try out * docker install script with snauth * fix param * fix * latest image * snauth output * use temporary docker image tags * use temporary docker image tag * open db port for testing * no apikey needed for sn webapp * no apikey needed for sn webapp (script) * fix devcert creation script * update image tag to preview --------- Co-authored-by: vn0804 <[email protected]> Co-authored-by: SN\plastic <[email protected]>
1 parent 8aa4076 commit baf2bff

File tree

16 files changed

+513
-68
lines changed

16 files changed

+513
-68
lines changed

deployment/install-sensenet.ps1

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Param (
2424
[Parameter(Mandatory=$False)]
2525
[switch]$LocalSn,
2626
[Parameter(Mandatory=$False)]
27-
[switch]$UseVolume,
27+
[switch]$UseVolume,
28+
[Parameter(Mandatory=$False)]
29+
[switch]$UseAuth,
2830

2931
# Hosting environment
3032
[Parameter(Mandatory=$False, DontShow=$True)]
@@ -263,19 +265,35 @@ if ($SnType -eq "InSql") {
263265
-ErrorAction stop
264266
}
265267

266-
& $PSScriptRoot/scripts/install-identity-server.ps1 `
267-
-ProjectName $ProjectName `
268-
-VolumeBasePath $VolumeBasePath `
269-
-Routing cnt `
270-
-AppEnvironment $AppEnvironment `
271-
-OpenPort $True `
272-
-SensenetPublicHost https://localhost:$SnHostPort `
273-
-IdentityPublicHost https://localhost:$IsHostPort `
274-
-IsHostPort $IsHostPort `
275-
-CertPass $CertPsw `
276-
-UseVolume $UseVolume `
277-
-DryRun $DryRun `
278-
-ErrorAction stop
268+
if ($UseAuth) {
269+
& $PSScriptRoot/scripts/install-snauth.ps1 `
270+
-ProjectName $ProjectName `
271+
-VolumeBasePath $VolumeBasePath `
272+
-Routing cnt `
273+
-AppEnvironment $AppEnvironment `
274+
-OpenPort $True `
275+
-SensenetPublicHost https://localhost:$SnHostPort `
276+
-IdentityPublicHost https://localhost:$IsHostPort `
277+
-IsHostPort $IsHostPort `
278+
-CertPass $CertPsw `
279+
-UseVolume $UseVolume `
280+
-DryRun $DryRun `
281+
-ErrorAction stop
282+
} else {
283+
& $PSScriptRoot/scripts/install-identity-server.ps1 `
284+
-ProjectName $ProjectName `
285+
-VolumeBasePath $VolumeBasePath `
286+
-Routing cnt `
287+
-AppEnvironment $AppEnvironment `
288+
-OpenPort $True `
289+
-SensenetPublicHost https://localhost:$SnHostPort `
290+
-IdentityPublicHost https://localhost:$IsHostPort `
291+
-IsHostPort $IsHostPort `
292+
-CertPass $CertPsw `
293+
-UseVolume $UseVolume `
294+
-DryRun $DryRun `
295+
-ErrorAction stop
296+
}
279297

280298
if ($SearchService) {
281299
& $PSScriptRoot/scripts/install-search-service.ps1 `
@@ -315,6 +333,7 @@ if ($SearchService) {
315333
-SearchService $SearchService `
316334
-RabbitServiceHost $RabbitServiceHost `
317335
-CertPass $CertPsw `
336+
-UseAuth $UseAuth `
318337
-UseVolume $UseVolume `
319338
-DryRun $DryRun `
320339
-ErrorAction stop
@@ -343,6 +362,8 @@ if ($SearchService) {
343362
Wait-SnApp -SnHostPort $SnHostPort -MaxTryNumber 2 -DryRun $DryRun -ErrorAction stop
344363
}
345364

365+
# & $PSScriptRoot/scripts/insert-apikey.ps1
366+
346367
if (-not $DryRun -and $OpenInBrowser) {
347368
Start-Process "https://admin.sensenet.com/?repoUrl=https%3A%2F%2Flocalhost%3A$SnHostPort"
348369
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
Param(
2+
[Parameter(Mandatory=$False)]
3+
[string]$RepoUrl="localhost:51016",
4+
[Parameter(Mandatory=$False)]
5+
[string]$AuthUrl="localhost:51017",
6+
[Parameter(Mandatory=$False)]
7+
[string]$DataSource="sensenet-insql-cdb-sndb",
8+
[Parameter(Mandatory=$False)]
9+
[string]$DataContainer="sensenet-insql-cdb-snsql",
10+
[Parameter(Mandatory=$False)]
11+
[switch]$StepByStep
12+
)
13+
14+
if (-not (Get-Command "Invoke-Cli" -DryRun $DryRun -ErrorAction SilentlyContinue)) {
15+
Write-Output "load helper functions"
16+
. "$($PSScriptRoot)/helper-functions.ps1"
17+
}
18+
19+
Test-Docker
20+
21+
$user="sa"
22+
$password="SuP3rS3CuR3P4sSw0Rd"
23+
24+
$clientId = "pr3Gen3R4Ted"
25+
$clientSecret = "pr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Ted"
26+
$apiKey = "pr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Ted"
27+
28+
# check if client exists
29+
$query = "SELECT * FROM [AccessTokens] WHERE [Value] = '$apiKey' AND [UserId] = 1 FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER"
30+
$params = "exec", $DataContainer, "/opt/mssql-tools/bin/sqlcmd", "-d", $DataSource, "-U", $user, "-P", $password, "-Q", $query
31+
$result = Invoke-Cli -execFile "docker" -params $params -ErrorAction SilentlyContinue
32+
if ($result -ne "" -and $result -ne $null -and $result.Count -gt 1 -and $result[2] -ne $null) {
33+
$obj = $result[2] | ConvertFrom-Json
34+
if ($obj -ne $null) {
35+
# Write-Host "ApiKey $($obj.Value) already exists."
36+
$apiKeyExists = $true
37+
}
38+
}
39+
40+
41+
# check if client exists
42+
$query = "SELECT * FROM [ClientApps] WHERE [ClientId] = '$($clientId)' AND [Authority] = '$authUrl' FOR JSON AUTO, WITHOUT_ARRAY_WRAPPER"
43+
$params = "exec", $DataContainer, "/opt/mssql-tools/bin/sqlcmd", "-d", $DataSource, "-U", $user, "-P", $password, "-Q", $query
44+
$result = Invoke-Cli -execFile "docker" -params $params -ErrorAction SilentlyContinue
45+
if ($result -ne "" -and $result -ne $null -and $result.Count -gt 1 -and $result[2] -ne $null) {
46+
$obj = $result[2] | ConvertFrom-Json
47+
if ($obj -ne $null) {
48+
# Write-Host "Client with ClientId $($obj.ClientId) already exists."
49+
$clientExists = $true
50+
}
51+
}
52+
53+
if ($apiKeyExists -and $clientExists) {
54+
Write-Host "Both Client with ClientId and ApiKey already exists."
55+
return
56+
}
57+
58+
# default values
59+
60+
$charSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
61+
$rndmId = -join (1..16 | ForEach-Object { Get-Random -InputObject $charSet.ToCharArray() })
62+
$creationDate = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fffffff"
63+
64+
# Check if apikey exists and insert or update accordingly
65+
$clientappScript = @"
66+
IF NOT EXISTS (SELECT 1 FROM [AccessTokens] WHERE [Value] = '$apiKey' AND [UserId] = 1)
67+
BEGIN
68+
INSERT INTO [AccessTokens]
69+
([UserId], [Value], [Feature], [CreationDate], [ExpirationDate])
70+
VALUES
71+
('1', '$apiKey', 'apikey', '$creationDate', '9999-12-31 23:59:59.9999999')
72+
END
73+
"@
74+
75+
$params = "exec", $DataContainer, "/opt/mssql-tools/bin/sqlcmd", "-d", $DataSource, "-U", $user, "-P", $password, "-Q", $clientappScript
76+
Invoke-Cli -execFile "docker" -params $params -ErrorAction Stop
77+
78+
# Check if clientapp exists and insert or update accordingly
79+
$clientappScript = @"
80+
IF EXISTS (SELECT 1 FROM [ClientApps] WHERE [ClientId] = '$clientId')
81+
BEGIN
82+
UPDATE [ClientApps]
83+
SET [Name] = '$clientId', [Repository] = '$repoUrl', [UserName] = 'builtin\admin', [Authority] = '$authUrl', [Type] = 4
84+
WHERE [ClientId] = '$clientId'
85+
END
86+
ELSE
87+
BEGIN
88+
INSERT INTO [ClientApps]
89+
([ClientId], [Name], [Repository], [UserName], [Authority], [Type])
90+
VALUES
91+
('$clientId', '$clientId', '$repoUrl', 'builtin\admin', '$authUrl', 4)
92+
END
93+
"@
94+
95+
$params = "exec", $DataContainer, "/opt/mssql-tools/bin/sqlcmd", "-d", $DataSource, "-U", $user, "-P", $password, "-Q", $clientappScript
96+
Invoke-Cli -execFile "docker" -params $params -ErrorAction Stop
97+
98+
# Check if client secret exists and insert or update accordingly
99+
$clientsecretScript = @"
100+
IF EXISTS (SELECT 1 FROM [ClientSecrets] WHERE [ClientId] = '$clientId')
101+
BEGIN
102+
UPDATE [ClientSecrets]
103+
SET [Value] = '$clientSecret', [CreationDate] = '$creationDate', [ValidTill] = '9999-12-31 23:59:59.9999999'
104+
WHERE [ClientId] = '$clientId'
105+
END
106+
ELSE
107+
BEGIN
108+
INSERT INTO [ClientSecrets]
109+
([Id], [ClientId], [Value], [CreationDate], [ValidTill])
110+
VALUES
111+
('$rndmId', '$clientId', '$clientSecret', '$creationDate', '9999-12-31 23:59:59.9999999')
112+
END
113+
"@
114+
115+
$params = "exec", $DataContainer, "/opt/mssql-tools/bin/sqlcmd", "-d", $DataSource, "-U", $user, "-P", $password, "-Q", $clientsecretScript
116+
Invoke-Cli -execFile "docker" -params $params -ErrorAction Stop
117+
118+

deployment/scripts/install-identity-server.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Param (
22
[Parameter(Mandatory=$False)]
33
[string]$ProjectName="docker",
44
[Parameter(Mandatory=$False)]
5-
[string]$NetworkName="snnetwork",
5+
[string]$NetworkName="sensenet",
66

77
# Hosting environment
88
[Parameter(Mandatory=$False)]
@@ -32,7 +32,7 @@ Param (
3232

3333
# Identity server
3434
[Parameter(Mandatory=$False)]
35-
[string]$IdentityDockerImage="sensenetcsp/sn-identityserver:latest",
35+
[string]$IdentityDockerImage="sensenetcsp/sn-identityserver:preview",
3636
[Parameter(Mandatory=$False)]
3737
[string]$IdentityContainerName="$($ProjectName)-snis",
3838
[Parameter(Mandatory=$False)]

deployment/scripts/install-rabbit.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Param (
22
[Parameter(Mandatory=$False)]
3-
[string]$NetworkName="snnetwork",
3+
[string]$NetworkName="sensenet",
44

55
# RabbitMq
66
[Parameter(Mandatory=$False)]

deployment/scripts/install-search-service.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Param (
22
[Parameter(Mandatory=$False)]
33
[string]$ProjectName="docker",
44
[Parameter(Mandatory=$False)]
5-
[string]$NetworkName="snnetwork",
5+
[string]$NetworkName="sensenet",
66

77
# Hosting environment
88
[Parameter(Mandatory=$False)]
@@ -38,7 +38,7 @@ Param (
3838

3939
# Search service parameters
4040
[Parameter(Mandatory=$False)]
41-
[string]$SearchDockerImage="sensenetcsp/sn-searchservice:latest",
41+
[string]$SearchDockerImage="sensenetcsp/sn-searchservice:preview",
4242
[Parameter(Mandatory=$False)]
4343
[string]$SearchContainerName="$($ProjectName)-snsearch",
4444
[Parameter(Mandatory=$False)]

deployment/scripts/install-sensenet-app.ps1

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Param (
22
[Parameter(Mandatory=$False)]
33
[string]$ProjectName="docker",
44
[Parameter(Mandatory=$False)]
5-
[string]$NetworkName="snnetwork",
5+
[string]$NetworkName="sensenet",
66

77
# Hosting environment
88
[Parameter(Mandatory=$False)]
@@ -26,14 +26,16 @@ Param (
2626
[Parameter(Mandatory=$False)]
2727
[string]$SnType="InSql",
2828
[Parameter(Mandatory=$False)]
29-
[string]$SensenetDockerImage="sensenetcsp/sn-api-sql:latest",
29+
[string]$SensenetDockerImage="sensenetcsp/sn-api-sql:preview",
3030
[Parameter(Mandatory=$False)]
3131
[string]$SensenetContainerName="$($ProjectName)-snapp",
3232
[Parameter(Mandatory=$False)]
3333
[string]$SensenetAppdataVolume="$($VolumeBasePath)/$($SensenetContainerName)/appdata",
3434
[Parameter(Mandatory=$False)]
3535
[string]$SensenetPublicHost="https://$($ProjectName)-sn.$($Domain)",
3636
[Parameter(Mandatory=$False)]
37+
[string]$HealthCheckUser="s3Cur3P4Ss",
38+
[Parameter(Mandatory=$False)]
3739
[int]$SnHostPort=8081,
3840
[Parameter(Mandatory=$False)]
3941
[int]$SnAppPort=443,
@@ -49,6 +51,10 @@ Param (
4951
[string]$IdentityPublicHost="https://$($ProjectName)-is.$($Domain)",
5052
[Parameter(Mandatory=$False)]
5153
[string]$IdentityContainerHost="http://$($IdentityContainerName)",
54+
[Parameter(Mandatory=$False)]
55+
[bool]$UseAuth,
56+
[Parameter(Mandatory=$False)]
57+
[string]$ApiKey = "pr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Tedpr3Gen3R4Ted",
5258

5359
# Sensenet Repository Database
5460
[Parameter(Mandatory=$False)]
@@ -126,14 +132,14 @@ $date = Get-Date -Format "yyyy-MM-dd HH:mm K"
126132

127133
switch ($SnType) {
128134
"InMem" {
129-
$SensenetDockerImage="sensenetcsp/sn-api-inmem:latest"
135+
$SensenetDockerImage="sensenetcsp/sn-api-inmem:preview"
130136
}
131137
"InSql" {
132138
if ($SearchService) {
133-
$SensenetDockerImage="sensenetcsp/sn-api-nlb:latest"
139+
$SensenetDockerImage="sensenetcsp/sn-api-nlb:preview"
134140
}
135141
else {
136-
$SensenetDockerImage="sensenetcsp/sn-api-sql:latest"
142+
$SensenetDockerImage="sensenetcsp/sn-api-sql:preview"
137143
}
138144
}
139145
Default {
@@ -173,13 +179,23 @@ $params = "run", "-it", "-d", "eol",
173179
"-e", "ASPNETCORE_URLS=$aspnetUrls", "eol",
174180
"-e", "ASPNETCORE_ENVIRONMENT=$AppEnvironment", "eol",
175181
"-e", "sensenet__Container__Name=$($SensenetContainerName)", "eol",
182+
"-e", "sensenet__apikeys__healthcheckeruser=$($HealthCheckUser)", "eol",
176183
"-e", "sensenet__identityManagement__UserProfilesEnabled=false", "eol",
177184
"-e", "sensenet__authentication__authServerType=$($AuthServerType)", "eol",
178185
"-e", "sensenet__authentication__authority=$($IdentityPublicHost)", "eol",
179186
"-e", "sensenet__authentication__repositoryUrl=$($SensenetPublicHost)", "eol",
180187
"-e", "sensenet__authentication__AddJwtCookie=$($JwtCookie)", "eol",
181188
"-e", "sensenet__apikeys__healthcheckeruser=$($HealthCheckUser)", "eol"
182189

190+
if ($UseAuth) {
191+
$params += "-e", "sensenet__authentication__authServerType=SNAuth", "eol",
192+
"-e", "sensenet__authentication__AddJwtCookie=false", "eol"
193+
} else {
194+
$params += "-e", "sensenet__authentication__authServerType=IdentityServer", "eol",
195+
"-e", "sensenet__authentication__AddJwtCookie=true", "eol",
196+
"-e", "sensenet__identityManagement__UserProfilesEnabled=false", "eol"
197+
}
198+
183199
if ($SnType -eq "InSql") {
184200
$params += "-e", "ConnectionStrings__SnCrMsSql=Persist Security Info=False;Initial Catalog=$($SqlDbName);Data Source=$($DataSource);User ID=$($SqlUser);Password=$($SqlPsw);TrustServerCertificate=true", "eol"
185201
}

deployment/scripts/install-sensenet-init.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Param (
22
[Parameter(Mandatory=$False)]
3-
[string]$NetworkName="snnetwork",
3+
[string]$NetworkName="sensenet",
44

55
# Docker
66
[Parameter(Mandatory=$False)]

0 commit comments

Comments
 (0)