Skip to content

Commit 7192557

Browse files
committed
Add troubleshooting guide, add kdc test to sample app
1 parent f23f147 commit 7192557

File tree

5 files changed

+69
-24
lines changed

5 files changed

+69
-24
lines changed

README.MD

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ applications:
1818
- name: TestKerberos
1919
path: bin/Debug/net5.0/publish
2020
random-route: true
21-
memory: 256M
21+
memory: 512M
2222
health-check-type: none
2323
buildpacks:
24-
- https://github.com/macsux/kerberos-buildpack/releases/download/v0.1.0/KerberosBuildpack-linux-x64-0.1.0.zip
24+
- https://github.com/macsux/kerberos-buildpack/releases/download/WIP/KerberosBuildpack-linux-x64-WIP.zip
2525
- dotnet_core_buildpack
2626
env:
2727
KRB5_KDC: ad.almirex.com
@@ -38,4 +38,37 @@ applications:
3838

3939
Core libraries used by .NET and Java apps use MIT Kerberos to do Kerberos (aka Integrated) authentication when running on Linux. This buildpack configures MIT Kerberos, and obtains the necessary initial TGT tickets necessary for the app to acquire authentication tickets.
4040

41-
A sidecar runs in background that will obtain tickets Kerberos .NET
41+
A sidecar runs in background that will obtain tickets Kerberos .NET
42+
43+
## Troubleshooting
44+
45+
Recommendation is to start with sample app included, which exposes the folowing endpoints:
46+
`/user` - which will authenticate incoming HTTP principal and print caller's identity. Simply call this endpoint on domain joined box from browser
47+
`sql` - tests kerberos connection to SQL Server. Set connection string either in `appsettings.json` or via environmental variable `CONNECTIONSTRINGS__SQLSERVER`.
48+
`/testkdc` - verify that connection can be established to KDC server on port 88.
49+
50+
After the app starts up you should see logs emitted from sidecar process that look like this:
51+
```csharp
52+
2022-01-26T16:04:52.80-0500 [PROXY/0] OUT Exit status 137
53+
2022-01-26T16:04:52.87-0500 [APP/PROC/WEB/0] OUT info: Microsoft.Hosting.Lifetime[14]
54+
2022-01-26T16:04:52.87-0500 [APP/PROC/WEB/0] OUT Now listening on: http://0.0.0.0:9090
55+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT info: Microsoft.Hosting.Lifetime[0]
56+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT Application started. Press Ctrl+C to shut down.
57+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT info: Microsoft.Hosting.Lifetime[0]
58+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT Hosting environment: Production
59+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT info: Microsoft.Hosting.Lifetime[0]
60+
2022-01-26T16:04:52.88-0500 [APP/PROC/WEB/0] OUT Content root path: /home/vcap/app/
61+
2022-01-26T16:04:53.23-0500 [APP/PROC/WEB/0] OUT info: KerberosSidecar.KerberosWorker[0]
62+
2022-01-26T16:04:53.23-0500 [APP/PROC/WEB/0] OUT Service authenticated successfully as 'iwaclient'
63+
2022-01-26T16:04:53.24-0500 [APP/PROC/WEB/0] OUT info: KerberosSidecar.Spn.LoggingSpnClient[0]
64+
2022-01-26T16:04:53.24-0500 [APP/PROC/WEB/0] OUT Ensure that the following SPN for the service exists: http/kerberosdemo.apps.longbeach.cf-app.com
65+
```
66+
67+
If you have not received a message similar to `Service authenticated successfully as 'iwaclient'`, it means that the worker sidecar has been unable to obtain ticket from your KDC.
68+
69+
#### Things to check
70+
71+
- Sidecar process started, as indicated by log entry containing `Now listening on: http://0.0.0.0:9090`. (note port 9090 - there maybe similar log entry but for port 8080 - that one is for the main app).
72+
- Credentials are correct and specified in the right format
73+
- KDC is accessible from the container. Use `/testkdc` endpoint of sample app to test.
74+
- Any other errors coming from the logs

sample/KerberosDemo/Controllers/HomeController.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net;
5+
using System.Net.NetworkInformation;
6+
using System.Net.Sockets;
47
using System.Security.Claims;
58
using System.Text;
69
using System.Threading.Tasks;
@@ -107,6 +110,30 @@ public ActionResult<string> SqlTest()
107110

108111
return sb.ToString();
109112
}
113+
114+
[HttpGet("/testkdc")]
115+
public async Task<string> TestKDC(string kdc)
116+
{
117+
118+
if (string.IsNullOrEmpty(kdc))
119+
{
120+
kdc = Environment.GetEnvironmentVariable("KRB5_KDC");
121+
if (string.IsNullOrEmpty(kdc))
122+
return "KRB5_KDC env var is not configured";
123+
}
124+
using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
125+
try
126+
{
127+
await socket.ConnectAsync(kdc, 88);
128+
return $"Successfully connected to {kdc} on port 88";
129+
}
130+
catch (Exception e)
131+
{
132+
return $"Failed connection test to {kdc} on port 88\n{e}";
133+
}
134+
}
135+
136+
110137
}
111138

112139
public class SqlServerInfo

sample/KerberosDemo/Properties/launchSettings.json

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
{
22
"$schema": "http://json.schemastore.org/launchsettings.json",
3-
"iisSettings": {
4-
"windowsAuthentication": false,
5-
"anonymousAuthentication": true,
6-
"iisExpress": {
7-
"applicationUrl": "http://localhost:13453",
8-
"sslPort": 44328
9-
}
10-
},
113
"profiles": {
12-
"IIS Express": {
13-
"commandName": "IISExpress",
14-
"launchBrowser": true,
15-
"launchUrl": "swagger",
16-
"environmentVariables": {
17-
"ASPNETCORE_ENVIRONMENT": "Development"
18-
}
19-
},
204
"KerberosDemo": {
215
"commandName": "Project",
226
"dotnetRunMessages": "true",
237
"launchBrowser": true,
248
"launchUrl": "swagger",
25-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
9+
"applicationUrl": "http://localhost:5000",
2610
"environmentVariables": {
27-
"ASPNETCORE_ENVIRONMENT": "Development"
11+
"ASPNETCORE_ENVIRONMENT": "Development",
12+
"KRB5_KDC": "dc1.macsux.com"
2813
}
2914
}
3015
}

sample/KerberosDemo/Startup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ public void ConfigureServices(IServiceCollection services)
4747
// .AddNegotiate(c => c
4848
// .EnableLdap(ldap =>
4949
// {
50-
ldap.LdapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapAddress, true, false), new NetworkCredential(serviceAccount, password), AuthType.Basic);
50+
// ldap.LdapConnection = new LdapConnection(new LdapDirectoryIdentifier(ldapAddress, true, false), new NetworkCredential(serviceAccount, password), AuthType.Basic);
5151
// ldap.Domain = domain;
5252
// ldap.LdapConnection.SessionOptions.ReferralChasing = ReferralChasingOptions.None;
5353
// ldap.LdapConnection.SessionOptions.ProtocolVersion = 3; //Setting LDAP Protocol to latest version
54-
ldap.LdapConnection.Timeout = TimeSpan.FromMinutes(1);
54+
// ldap.LdapConnection.Timeout = TimeSpan.FromMinutes(1);
5555
// ldap.LdapConnection.AutoBind = true;
5656
// ldap.LdapConnection.Bind();
5757
// }));

sample/KerberosDemo/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
applications:
33
- name: KerberosDemo
44
path: bin/Debug/net5.0/linux-x64/publish
5-
memory: 256M
5+
memory: 512M
66
health-check-type: none
77
buildpacks:
88
- https://github.com/macsux/kerberos-buildpack/releases/download/WIP/KerberosBuildpack-linux-x64-WIP.zip

0 commit comments

Comments
 (0)