-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/pam extension support #12
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
29776d5
Merge pull request #11 from Keyfactor/release-2.0
spbsoluble c4dd4ca
Added Pam Extension support for inventory and management jobs
CoconutMage 4780ea2
docs: auto-generate README and documentation [skip ci]
github-actions[bot] 7d1abce
Dummy Commit
CoconutMage 46557f6
docs: auto-generate README and documentation [skip ci]
github-actions[bot] cba9c9d
[skip ci] Update keyfactor-release-workflow.yml
indrora dbdc250
Merge branch 'release-2.0' into feat/pam-extension-support
CoconutMage 6abb465
Changelog + logging change
CoconutMage 1b5b3f2
docs: auto-generate README and documentation [skip ci]
github-actions[bot] 2945e0d
Removed secret logging
CoconutMage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| # v2.0.1 | ||
| - Added PAM resolution support | ||
| # v2.0.0 | ||
| - .Net 6 and .Net 8 Support and Documentation Updates | ||
| # v1.0.0 | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,126 +1,133 @@ | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Xml.Serialization; | ||
| using Keyfactor.Extensions.Orchestrator.Kemp.Client; | ||
| using Keyfactor.Extensions.Orchestrator.Kemp.Client.Models; | ||
| using Keyfactor.Logging; | ||
| using Keyfactor.Orchestrators.Common.Enums; | ||
| using Keyfactor.Orchestrators.Extensions; | ||
| using Microsoft.Extensions.Logging; | ||
| using Newtonsoft.Json; | ||
|
|
||
| namespace Keyfactor.Extensions.Orchestrator.Kemp.Jobs | ||
| { | ||
| public class Inventory : IInventoryJobExtension | ||
| { | ||
| private readonly ILogger<Inventory> _logger; | ||
|
|
||
| public Inventory(ILogger<Inventory> logger) | ||
| { | ||
| _logger = logger; | ||
| } | ||
|
|
||
| public string ExtensionName => "Kemp"; | ||
|
|
||
| public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, | ||
| SubmitInventoryUpdate submitInventoryUpdate) | ||
| { | ||
| try | ||
| { | ||
| _logger.MethodEntry(); | ||
| return PerformInventory(jobConfiguration, submitInventoryUpdate); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _logger.LogError($"Error occured in Inventory.ProcessJob: {LogHandler.FlattenException(e)}"); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInventoryUpdate submitInventory) | ||
| { | ||
| try | ||
| { | ||
| _logger.MethodEntry(LogLevel.Debug); | ||
| _logger.LogTrace($"Inventory Config {JsonConvert.SerializeObject(config)}"); | ||
| _logger.LogTrace( | ||
| $"Client Machine: {config.CertificateStoreDetails.ClientMachine} ApiKey: {config.ServerPassword}"); | ||
|
|
||
| var client = new KempClient(config); | ||
|
|
||
| var certificatesResult = client.GetCertificates().Result; | ||
| var intermediateCertificates = client.GetIntermediateCertificates().Result; | ||
|
|
||
| //Debug Write Certificate List Response from Palo Alto | ||
| var listWriter = new StringWriter(); | ||
| var listSerializer = new XmlSerializer(typeof(CertListResponse)); | ||
| listSerializer.Serialize(listWriter, certificatesResult); | ||
| _logger.LogTrace($"Certificate List Result {listWriter}"); | ||
|
|
||
| //Debug Write Intermediate Certificate List Response from Palo Alto | ||
| var intListWriter = new StringWriter(); | ||
| var intListSerializer = new XmlSerializer(typeof(CertListResponse)); | ||
| intListSerializer.Serialize(intListWriter, intermediateCertificates); | ||
| _logger.LogTrace($"Intermediate List Result {intListWriter}"); | ||
|
|
||
| var inventoryItems = (from cert in certificatesResult?.Success?.Data?.Certs | ||
| let certPem = client.GetCertificate(cert.Name).Result | ||
| select BuildInventoryItem(cert.Name, certPem.Success.Data.Certificate, true)).ToList(); | ||
| inventoryItems.AddRange(from cert in intermediateCertificates?.Success?.Data?.Certs | ||
| let certPem = client.GetIntermediateCertificate(cert.Name).Result | ||
| select BuildInventoryItem(cert.Name, certPem.Success.Data.Certificate, false)); | ||
|
|
||
| _logger.LogTrace("Submitting Inventory To Keyfactor via submitInventory.Invoke"); | ||
| submitInventory.Invoke(inventoryItems); | ||
| _logger.LogTrace("Submitted Inventory To Keyfactor via submitInventory.Invoke"); | ||
|
|
||
| _logger.MethodExit(LogLevel.Debug); | ||
|
|
||
| _logger.LogTrace("Return Success"); | ||
| return new JobResult | ||
| { | ||
| Result = OrchestratorJobStatusJobResult.Success, | ||
| JobHistoryId = config.JobHistoryId, | ||
| FailureMessage = "" | ||
| }; | ||
| } | ||
| catch (Exception e) | ||
| using Keyfactor.Extensions.Orchestrator.Kemp.Client; | ||
| using Keyfactor.Extensions.Orchestrator.Kemp.Client.Models; | ||
| using Keyfactor.Logging; | ||
| using Keyfactor.Orchestrators.Common.Enums; | ||
| using Keyfactor.Orchestrators.Extensions; | ||
| using Keyfactor.Orchestrators.Extensions.Interfaces; | ||
| using Microsoft.Extensions.Logging; | ||
| using Newtonsoft.Json; | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Xml.Linq; | ||
| using System.Xml.Serialization; | ||
| using static Org.BouncyCastle.Math.EC.ECCurve; | ||
|
|
||
| namespace Keyfactor.Extensions.Orchestrator.Kemp.Jobs | ||
| { | ||
| public class Inventory : IInventoryJobExtension | ||
| { | ||
| public IPAMSecretResolver _resolver; | ||
| public string ExtensionName => "Kemp"; | ||
| private ILogger _logger; | ||
|
|
||
| public Inventory(IPAMSecretResolver resolver) | ||
| { | ||
| _resolver = resolver; | ||
| } | ||
|
|
||
| public JobResult ProcessJob(InventoryJobConfiguration jobConfiguration, SubmitInventoryUpdate submitInventoryUpdate) | ||
| { | ||
| _logger = LogHandler.GetClassLogger(this.GetType()); | ||
| _logger.MethodEntry(); | ||
|
|
||
| try | ||
| { | ||
| return new JobResult | ||
| { | ||
| Result = OrchestratorJobStatusJobResult.Failure, | ||
| JobHistoryId = config.JobHistoryId, | ||
| FailureMessage = LogHandler.FlattenException(e) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| protected virtual CurrentInventoryItem BuildInventoryItem(string alias, string certPem, bool privateKey) | ||
| { | ||
| try | ||
| { | ||
| _logger.MethodEntry(); | ||
| _logger.LogTrace($"Alias: {alias} Pem: {certPem} PrivateKey: {privateKey}"); | ||
|
|
||
|
|
||
| var acsi = new CurrentInventoryItem | ||
| { | ||
| Alias = alias, | ||
| Certificates = new[] {certPem}, | ||
| ItemStatus = OrchestratorInventoryItemStatus.Unknown, | ||
| PrivateKeyEntry = privateKey, | ||
| UseChainLevel = false | ||
| }; | ||
|
|
||
| _logger.MethodExit(); | ||
| return acsi; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _logger.LogError($"Error Occurred in Inventory.BuildInventoryItem: {LogHandler.FlattenException(e)}"); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| string password = PAMUtilities.ResolvePAMField(_resolver, _logger, "Kemp ApiKey", jobConfiguration.ServerPassword); | ||
| jobConfiguration.ServerPassword = password; | ||
|
|
||
| return PerformInventory(jobConfiguration, submitInventoryUpdate); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _logger.LogError($"Error occured in Inventory.ProcessJob: {LogHandler.FlattenException(e)}"); | ||
| throw; | ||
| } | ||
| } | ||
|
|
||
| private JobResult PerformInventory(InventoryJobConfiguration config, SubmitInventoryUpdate submitInventory) | ||
| { | ||
| try | ||
| { | ||
| _logger.MethodEntry(LogLevel.Debug); | ||
|
|
||
| _logger.LogTrace( | ||
| $"Client Machine: {config.CertificateStoreDetails.ClientMachine} ApiKey: *********"); | ||
|
|
||
| var client = new KempClient(config); | ||
|
|
||
| var certificatesResult = client.GetCertificates().Result; | ||
| var intermediateCertificates = client.GetIntermediateCertificates().Result; | ||
|
|
||
| //Debug Write Certificate List Response from Palo Alto | ||
| var listWriter = new StringWriter(); | ||
| var listSerializer = new XmlSerializer(typeof(CertListResponse)); | ||
| listSerializer.Serialize(listWriter, certificatesResult); | ||
| _logger.LogTrace($"Certificate List Result {listWriter}"); | ||
|
|
||
| //Debug Write Intermediate Certificate List Response from Palo Alto | ||
| var intListWriter = new StringWriter(); | ||
| var intListSerializer = new XmlSerializer(typeof(CertListResponse)); | ||
| intListSerializer.Serialize(intListWriter, intermediateCertificates); | ||
| _logger.LogTrace($"Intermediate List Result {intListWriter}"); | ||
|
|
||
| var inventoryItems = (from cert in certificatesResult?.Success?.Data?.Certs | ||
| let certPem = client.GetCertificate(cert.Name).Result | ||
| select BuildInventoryItem(cert.Name, certPem.Success.Data.Certificate, true)).ToList(); | ||
| inventoryItems.AddRange(from cert in intermediateCertificates?.Success?.Data?.Certs | ||
| let certPem = client.GetIntermediateCertificate(cert.Name).Result | ||
| select BuildInventoryItem(cert.Name, certPem.Success.Data.Certificate, false)); | ||
|
|
||
| _logger.LogTrace("Submitting Inventory To Keyfactor via submitInventory.Invoke"); | ||
| submitInventory.Invoke(inventoryItems); | ||
| _logger.LogTrace("Submitted Inventory To Keyfactor via submitInventory.Invoke"); | ||
|
|
||
| _logger.MethodExit(LogLevel.Debug); | ||
|
|
||
| _logger.LogTrace("Return Success"); | ||
| return new JobResult | ||
| { | ||
| Result = OrchestratorJobStatusJobResult.Success, | ||
| JobHistoryId = config.JobHistoryId, | ||
| FailureMessage = "" | ||
| }; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| return new JobResult | ||
| { | ||
| Result = OrchestratorJobStatusJobResult.Failure, | ||
| JobHistoryId = config.JobHistoryId, | ||
| FailureMessage = LogHandler.FlattenException(e) | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| protected virtual CurrentInventoryItem BuildInventoryItem(string alias, string certPem, bool privateKey) | ||
| { | ||
| try | ||
| { | ||
| _logger.MethodEntry(); | ||
| _logger.LogTrace($"Alias: {alias} Pem: {certPem} PrivateKey: *******"); | ||
|
|
||
|
|
||
| var acsi = new CurrentInventoryItem | ||
| { | ||
| Alias = alias, | ||
| Certificates = new[] {certPem}, | ||
| ItemStatus = OrchestratorInventoryItemStatus.Unknown, | ||
| PrivateKeyEntry = privateKey, | ||
| UseChainLevel = false | ||
| }; | ||
|
|
||
| _logger.MethodExit(); | ||
| return acsi; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _logger.LogError($"Error Occurred in Inventory.BuildInventoryItem: {LogHandler.FlattenException(e)}"); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.