-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for credhub binding of kerberos credentials on cloud foundry
- Loading branch information
Showing
8 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ applications: | |
|
||
``` | ||
|
||
|
||
** 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. | ||
|
||
## How it works | ||
|
@@ -43,6 +42,65 @@ Core libraries used by .NET and Java apps use MIT Kerberos to do Kerberos (aka I | |
|
||
A sidecar runs in background that will obtain tickets Kerberos .NET | ||
|
||
## Secure credentials with CredHub integration | ||
|
||
Instead of of injecting service credentials as environmental variables, this buildpack supports injecting it securely via CredHub integration. This will safely store creds associated with the app inside CredHub, and they will be injected as environmental variables when container starts. This will be only visible from the app - they will not be visible if the user tries to query environmental variables associated with the app. | ||
|
||
#### Prerequisite: [CredHub service broker](https://network.tanzu.vmware.com/products/credhub-service-broker) installed on the platform | ||
|
||
1. Omit KRB_SERVICE_ACCOUNT / KRB_PASSWORD from the manifest | ||
|
||
2. Create a file creds.json that looks similar to this: | ||
|
||
```json | ||
{ | ||
"ServiceAccount": "[email protected]", | ||
"Password": "P@ssw0rd" | ||
} | ||
``` | ||
|
||
3. Create a CredHub service instance that carries the above credentials as following: | ||
|
||
``` | ||
cf create-service credhub default CREDS_SERVICE_INSTANCE_NAME -c .\creds.json -t kerberos-service-principal | ||
``` | ||
|
||
4. Bind the credentials to the app | ||
|
||
``` | ||
cf bind-service APP_NAME CREDS_SERVICE_INSTANCE_NAME | ||
``` | ||
|
||
5. Push the app | ||
|
||
## Embedding Kerberos configuration into buildpack | ||
|
||
By default the buildpack will attempt to generate an MIT Kerberos configuration file (krb5.conf) out of combination of KRB5_KDC and the realm portion of the service account (everything after `@`). This may not be sufficient in more complex environments and require full control of the `krb5.conf` to properly work. It may also be desirable to not have to include location of the KDC in the push manifest. In order to support these scenarios, the buildpack allows embedding `krb5.conf` before being deployed on the platform. This has the advantage of being uniformly applied to all apps and move control over this file in the hands of central platform operator. In order to include environment specific `krb5.conf` in the buildpack, it must be placed into the buildpack zip file under `/deps/.krb5/krb5.conf`. This can be accomplished by creating a local directory structure that looks like this: | ||
|
||
``` | ||
. | ||
├── KerberosBuildpack-linux-x64-v1.0.0.zip | ||
├── deps | ||
│ └── .krb5 | ||
│ └── krb5.conf | ||
``` | ||
|
||
After run the following command to patch the zip file with config file: | ||
|
||
Powershell | ||
|
||
``` | ||
Compress-Archive -Update -Path deps -DestinationPath KerberosBuildpack-linux-x64-v1.0.0.zip | ||
``` | ||
|
||
Linux shell | ||
|
||
``` | ||
zip -ur KerberosBuildpack-linux-x64-v1.0.0.zip deps | ||
``` | ||
|
||
|
||
|
||
## Troubleshooting | ||
|
||
Recommendation is to start with sample app included, which exposes the folowing endpoints: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
applications: | ||
- name: KerberosDemo | ||
path: bin/Debug/net5.0/publish | ||
memory: 512M | ||
health-check-type: none | ||
buildpacks: | ||
- https://github.com/macsux/kerberos-buildpack/releases/download/WIP/KerberosBuildpack-linux-x64-WIP.zip | ||
- dotnet_core_buildpack | ||
env: | ||
KRB5_KDC: dc1.macsux.com | ||
KRB_SERVICE_ACCOUNT: "" | ||
KRB_PASSWORD: "" | ||
ConnectionStrings__SqlServer: Server=dc1.macsux.com;Database=master;Trusted_Connection=True;TrustServerCertificate=True |
22 changes: 22 additions & 0 deletions
22
src/KerberosSidecar/CloudFoundry/ConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace KerberosSidecar.CloudFoundry; | ||
|
||
public static class ConfigurationExtensions | ||
{ | ||
public static IEnumerable<ServiceBinding> GetServiceBindings(this IConfiguration config) | ||
{ | ||
return config.GetSection("vcap:services").GetChildren().SelectMany(serviceTypeSection => | ||
{ | ||
var serviceType = serviceTypeSection.Key; | ||
|
||
return serviceTypeSection.Get<List<ServiceBinding>>(c => | ||
{ | ||
c.BindNonPublicProperties = true; | ||
}) | ||
.Select(x => | ||
{ | ||
x.Type = serviceType; | ||
return x; | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using JetBrains.Annotations; | ||
|
||
#nullable disable | ||
namespace KerberosSidecar.CloudFoundry; | ||
|
||
[PublicAPI] | ||
[SuppressMessage("ReSharper", "InconsistentNaming")] | ||
public class ServiceBinding | ||
{ | ||
public string Name { get; set; } | ||
public string Type {get;set;} | ||
public string Plan { get; set; } | ||
public IConfigurationSection Credentials { get; set; } | ||
public T GetCredentials<T>() => Credentials.Get<T>(); | ||
public List<string> Tags {get;set;} | ||
public string SyslogDrainUrl {get;set;} | ||
private string Syslog_Drain_Url { set => SyslogDrainUrl = value; } | ||
public string Provider {get;set;} | ||
public string Label {get;set;} | ||
public string InstanceName { get; set; } | ||
private string Instance_Name { set => InstanceName = value; } | ||
public string BindingName {get;set;} | ||
private string Binding_Name { set => BindingName = value; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#nullable disable | ||
using JetBrains.Annotations; | ||
|
||
namespace KerberosSidecar.CloudFoundry; | ||
|
||
[PublicAPI] | ||
public class ServiceCredentials | ||
{ | ||
public string ServiceAccount { get; set; } | ||
public string Password { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters