Skip to content

Commit ba189cc

Browse files
committed
Add extract logs to buildpack
1 parent bb85cdf commit ba189cc

File tree

9 files changed

+42
-24
lines changed

9 files changed

+42
-24
lines changed

README.MD

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ applications:
2121
memory: 512M
2222
health-check-type: none
2323
buildpacks:
24-
- https://github.com/macsux/kerberos-buildpack/releases/download/WIP/KerberosBuildpack-linux-x64-WIP.zip
24+
- https://github.com/macsux/kerberos-buildpack/releases/download/v1.0.6/KerberosBuildpack-linux-x64-v1.0.6.zip
2525
- dotnet_core_buildpack
2626
env:
2727
KRB5_KDC: ad.almirex.com
@@ -30,6 +30,8 @@ applications:
3030

3131
```
3232

33+
** Adjust URL of the Kerberos buildpack to latest version. You can get the full zip URL from [Releases](https://github.com/macsux/kerberos-buildpack/releases) page.
34+
3335
## How it works
3436

3537
![](./docs/img/architecture.jpg)
@@ -49,26 +51,22 @@ Recommendation is to start with sample app included, which exposes the folowing
4951

5052
After the app starts up you should see logs emitted from sidecar process that look like this:
5153
```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
54+
2022-01-26T19:04:14.26-0500 [APP/PROC/WEB/0] OUT info: KerberosSidecar[0]
55+
2022-01-26T19:04:14.26-0500 [APP/PROC/WEB/0] OUT Kerberos sidecar started....
56+
2022-01-26T19:04:14.74-0500 [APP/PROC/WEB/0] OUT info: KerberosSidecar.KerberosWorker[0]
57+
2022-01-26T19:04:14.74-0500 [APP/PROC/WEB/0] OUT Service authenticated successfully as 'iwaclient'
58+
2022-01-26T19:04:14.75-0500 [APP/PROC/WEB/0] OUT info: KerberosSidecar.Spn.LoggingSpnClient[0]
59+
2022-01-26T19:04:14.75-0500 [APP/PROC/WEB/0] OUT Ensure that the following SPN for the service exists: http/kerberosdemo.apps.longbeach.cf-app.com
6560
```
6661

62+
* sidecar logs may be intermixed with app logs
63+
6764
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.
6865

6966
#### Things to check
7067

7168
- 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).
7269
- Credentials are correct and specified in the right format
7370
- KDC is accessible from the container. Use `/testkdc` endpoint of sample app to test.
74-
- Any other errors coming from the logs
71+
- Acquire additional logging from sidercar by turning up Kerberos related log verbosity by adding the following env var:
72+
- `Logging__LogLevel__Kerberos: Debug`

build/Build.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO.Compression;
55
using System.Linq;
66
using System.Runtime.CompilerServices;
7+
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
89
using ICSharpCode.SharpZipLib.Zip;
910
using NuGet.Configuration;
@@ -141,10 +142,14 @@ public bool IsGitHubRepository
141142
.Executes(() =>
142143
{
143144
var demoProjectDirectory = RootDirectory / "sample" / "KerberosDemo";
144-
DotNetPublish(c => c
145-
.SetProject(demoProjectDirectory / "KerberosDemo.csproj")
146-
.SetConfiguration("DEBUG"));
145+
// DotNetPublish(c => c
146+
// .SetProject(demoProjectDirectory / "KerberosDemo.csproj")
147+
// .SetConfiguration("DEBUG"));
147148
var publishFolder = demoProjectDirectory / "bin" / "Debug" / "net5.0" / "publish";
149+
var manifestFile = publishFolder / "manifest.yml";
150+
var manifest = File.ReadAllText(manifestFile);
151+
manifest = manifest.ReplaceRegex(@"\r?\n\s*path:.+", match => match.Result(""));
152+
File.WriteAllText(manifestFile, manifest);
148153
var artifactZip = ArtifactsDirectory / $"sampleapp-{Runtime}-{ReleaseName}.zip";
149154
DeleteFile(artifactZip);
150155
ZipFile.CreateFromDirectory(publishFolder, artifactZip, CompressionLevel.NoCompression, false);
@@ -194,7 +199,7 @@ public bool IsGitHubRepository
194199
{
195200
var zipPackageLocation = ArtifactsDirectory / artifact;
196201
var stream = File.OpenRead(zipPackageLocation);
197-
var releaseAssetUpload = new ReleaseAssetUpload(PackageZipName, "application/zip", stream, TimeSpan.FromHours(1));
202+
var releaseAssetUpload = new ReleaseAssetUpload(artifact, "application/zip", stream, TimeSpan.FromHours(1));
198203
var releaseAsset = await client.Repository.Release.UploadAsset(release, releaseAssetUpload);
199204

200205
Logger.Block(releaseAsset.BrowserDownloadUrl);

sample/KerberosDemo/KerberosDemo.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
1212
</ItemGroup>
1313

14+
<ItemGroup>
15+
<None Update="manifest.yml">
16+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
17+
</None>
18+
</ItemGroup>
19+
1420
</Project>

sample/KerberosDemo/appsettings.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"Logging": {
33
"LogLevel": {
4-
"Default": "Debug",
5-
"Microsoft": "Debug",
4+
"Default": "Information",
5+
"Microsoft": "Warning",
66
"Microsoft.Hosting.Lifetime": "Information"
77
}
88
},

sample/KerberosDemo/manifest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ applications:
55
memory: 512M
66
health-check-type: none
77
buildpacks:
8-
- https://github.com/macsux/kerberos-buildpack/releases/download/WIP/KerberosBuildpack-linux-x64-WIP.zip
8+
- https://github.com/macsux/kerberos-buildpack/releases/download/v1.0.6/KerberosBuildpack-linux-x64-v1.0.6.zip
99
- dotnet_core_buildpack
1010
env:
1111
KRB5_KDC: dc1.macsux.com

src/KerberosBuildpack/KerberosBuildpack.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class KerberosBuildpack : SupplyBuildpack
2323

2424
protected override void Apply(AbsolutePath buildPath, AbsolutePath cachePath, AbsolutePath depsPath, int index)
2525
{
26+
Console.WriteLine("==== Installing Kerberos Buildpack ==== ");
2627
var myDependenciesDirectory = depsPath / index.ToString(); // store any runtime dependencies not belonging to the app in this directory
2728
var krb5Dir = buildPath / ".krb5";
2829

@@ -38,13 +39,16 @@ protected override void Apply(AbsolutePath buildPath, AbsolutePath cachePath, Ab
3839
var sidecarTargetDir = myDependenciesDirectory / "sidecar";
3940

4041
FileSystemTasks.CopyDirectoryRecursively(sidecarSrcDir, sidecarTargetDir, DirectoryExistsPolicy.Merge, FileExistsPolicy.Overwrite);
42+
Console.WriteLine($"Sidecar process copied into $HOME/deps/{index}/sidecar");
4143

4244
var profiled = buildPath / ".profile.d";
4345
FileSystemTasks.EnsureExistingDirectory(profiled);
4446
var startSidecarScript = File.ReadAllText(currentAssemblyDir / "startsidecar.sh");
4547
startSidecarScript = startSidecarScript.Replace("@index", index.ToString());
46-
var startSidecarScriptPath = profiled / $"{index:00}_{nameof(KerberosBuildpack)}_startsidecar.sh";
48+
var startupScriptName = $"{index:00}_{nameof(KerberosBuildpack)}_startsidecar.sh";
49+
var startSidecarScriptPath = profiled / startupScriptName;
4750
File.WriteAllText(startSidecarScriptPath, startSidecarScript);
51+
Console.WriteLine($"Sidecar process startup script installed into $HOME/app/profile.d/{startupScriptName}");
4852
// below code attempts to use official way to introduce sidecar via buildpack as described here https://docs.cloudfoundry.org/buildpacks/sidecar-buildpacks.html
4953
// except it doesn't work and staging never completes - just hands with no error. workaround for now is to have process started as a background executable
5054
// stuffed into .profile.d startup script, but this makes logs emitted by sidecar show up as if originating from app

src/KerberosBuildpack/startsidecar.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
#set -ux
33
#set +e
4+
cd $DEPS_DIR/0/sidecar/
45
$DEPS_DIR/0/sidecar/KerberosSidecar --urls=http://0.0.0.0:9090 &
56

67
#

src/KerberosSidecar/KerberosSidecar.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20-
<None Include="appsettings.Development.yaml" CopyToPublishDirectory="Never"/>
20+
<None Include="appsettings.Development.yaml" CopyToPublishDirectory="Never" />
21+
<None Update="appsettings.yaml">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
2124
</ItemGroup>
2225

2326
</Project>

src/KerberosSidecar/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@
110110
{
111111
endpoints.MapHealthChecks("/health/ready", new HealthCheckOptions().WithJsonDetails());
112112
});
113+
app.Logger.LogInformation("Kerberos sidecar started....");
113114
await app.RunAsync();

0 commit comments

Comments
 (0)