- Community Home
- >
- Software
- >
- HPE Morpheus Software
- >
- HPE Morpheus Enterprise
- >
- Creating a custom Task Plugin that can access secr...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 03:36 AM
10-11-2023 03:36 AM
Creating a custom Task Plugin that can access secrets from Cypher and HashiCorp Vault
Hello,
This post will show you how to access cypher secrets from within a Morpheus Plugin per the 0.15.2 plugin-api. The example I have created will obtain secrets both from the internal Cypher vault, and also from HashiCorp Vault. This example uses the HashiCorp Vault Cypher plugin, and you can find more information on this plugin here: HashiCorp Vault Cypher Plugin. This example contains changes that will be operational and supported in the upcoming Morpheus version 6.2.3
Here is the use-case for this example:
- I want a task plugin that when executed in local context will print the value of two secrets.
- The first secret needs to be obtained from HashiCorp Vault
- The second secret needs to be obtained from the internal Morpheus Cypher Vault.
- The second secret should only be accessible from the user that created the cypher entry.
Based on this use-case, here is a snippet of the code from a task plugin provider to achieve this:
TaskResult executeLocalTask(Task task, Map opts, Container container, ComputeServer server, Instance instance) {
TaskConfig config = buildLocalTaskConfig([:], task, [], opts).blockingGet()
def cypherAccess1 = new CypherAccess(task.account)
def secret1 = this.morpheus.getCypher().read(cypherAccess1, "vault/KV1/secret/morpheus-credentials/access-secret-key")?.blockingGet()
User userExecutingTask
def secret2
if(config.userId) {
//setting userExecutingTask for cypher access restrictions
userExecutingTask = new User([id:config.userId?.toLong()])
def cypherAccess2 = new CypherAccess(task.account, "", userExecutingTask)
secret2 = this.morpheus.getCypher().read(cypherAccess2, "secret/company/accessKey")?.blockingGet() //only user who created this cypher entry and is executing this task can access.
}
opts.secret1 = secret1
opts.secret2 = secret2
executeTask(task, config, opts)
}
static TaskResult executeTask(Task task, TaskConfig config, Map opts) {
def sout = "Secret1: ${opts.secret1}, Secret2: ${opts.secret2}"
def serr = ""
new TaskResult(
success: true,
data : sout,
output : sout,
error : serr
)
Here is what the output will look like when executing the task: Screen Capture on 2023-09-12 at 15-35-10.mp4 - Droplr. The task is first executed by the user who created the second secret cypher entry, and the value is accessible as expected. The task is then executed by a user who did not create the cypher entry, and the value is NOT accessible as expected.