Skip to content

Commit f9aa673

Browse files
authored
Merge pull request #137 from jvanhill/IGN14040
IGN-14040: Create initial example user source profile and secret provider modules.
2 parents 89e168e + 529739b commit f9aa673

File tree

27 files changed

+2185
-2
lines changed

27 files changed

+2185
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ Adds a datasource to the report designer that can retrieve JSON data via a REST
4848
##### [Scripting Function (RPC)](scripting-function)
4949
Adds a system.example.multiply script that can be executed from both a client and a Gateway. Also demonstrates how the client can call a method in the Gateway via RPC.
5050

51+
##### [Secret Provider](secret-provider)
52+
Adds a Secret Provider that allows you to store and retrieve secrets in the Gateway. The secrets are stored in a Mongo DB backend.
53+
5154
##### [Slack Alarm Notification](slack-alarm-notification)
5255
Adds a Slack Alarm Notification type that handles alarm notifications through Slack's outgoing webhooks.
5356

57+
##### [User Source Profile](user-source-profile)
58+
Adds a User Source Profile that allows you to manage users and roles in the Gateway. Users and roles stored in a Mongo DB backend.
59+
5460
##### [Vision Component](vision-component)
5561
Creates a Hello World component that can be dragged onto a window in the Designer.
5662

secret-provider/.gitignore

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# A general .gitignore for Gradle or Maven built Ignition SDK projects that
2+
# use IntelliJ or Eclipse as an IDE
3+
4+
# Ignition Module files
5+
*.modl
6+
7+
# Java class files
8+
*.class
9+
10+
# generated files
11+
bin/
12+
gen/
13+
14+
# Local configuration file used for proj. specific settings (sdk paths, etc)
15+
local.properties
16+
17+
# Eclipse project files
18+
.classpath
19+
.project
20+
21+
# Intellij project files
22+
*.iml
23+
*.ipr
24+
*.iws
25+
.idea/
26+
27+
# git repos
28+
.git/
29+
30+
# hg repos
31+
.hg/
32+
33+
# Maven related
34+
*/target/
35+
*.versionsBackup
36+
37+
# Gradle related files and caches
38+
.gradletasknamecache
39+
.gradle/
40+
build/

secret-provider/README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Secret Provider
2+
3+
This module provides an example implementation of the `SecretProvider` interface, which allows for the use of stored
4+
secrets by Ignition. It is backed by a MongoDB backend, and the secrets are expected to be stored in the MongoDB
5+
database as the JSON returned from `SystemEncryptionService.entryToJson(Plaintext)`.
6+
7+
In a production environment, you may want to use the MongoDB Connector module, but for simplicity, this module uses the
8+
MongoDB Java driver directly. This allows for easy testing without the need to add another module to Ignition.
9+
10+
This implementation is set up for easy testing, and the default configuration should connect to a local, unsecured
11+
MongoDB. To start one in a Docker container, run:
12+
13+
```bash
14+
docker run -d -p 27017:27017 --rm --name insecure-mongo mongo
15+
```
16+
17+
Should you wish to start a MongoDB instance requiring authentication, you can use the following command. Remember
18+
to replace `admin` and `secret` with your desired username and password and configure your secret provider to use these
19+
credentials.
20+
21+
```bash
22+
docker run -d -p 27017:27017 --rm --name secure-mongo \
23+
-e MONGO_INITDB_ROOT_USERNAME=admin \
24+
-e MONGO_INITDB_ROOT_PASSWORD=secret \
25+
mongo
26+
```
27+
28+
## Adding Secrets to MongoDB
29+
30+
Since there is currently no write method for SecretProvider, you will need to populate the database with secrets
31+
manually.
32+
33+
### Encrypting Secrets
34+
First, generate a secret calling the Ignition system encryption REST API. Your API token will need to have Gateway
35+
write permissions, and you will need to replace `password` with the secret you want to encrypt.
36+
37+
```bash
38+
curl -s -H "Content-Type: text/plain" -H "X-Ignition-API-Token: ${API_TOKEN}" \
39+
http://localhost:8088/data/api/v1/encryption/encrypt -d password | json_pp
40+
```
41+
42+
Which will result in a response similar to the following:
43+
44+
```json
45+
{
46+
"ciphertext" : "NhkoviQxLsUZ2g",
47+
"encrypted_key" : "fYxDhnE_nKXiWGwGBJVaEWhojeg7duY3Y3G4dF89sKdjuf5iiX2nKw",
48+
"iv" : "TTGQPncN-rlf70Bq",
49+
"protected" : "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIiwiaWF0IjoxNzU1NjM0NDg3LCJ6aXAiOiJERUYifQ",
50+
"tag" : "sMU9-vhCyWHxLCH190eQ3A"
51+
}
52+
```
53+
54+
### Inserting Secrets into MongoDB
55+
56+
Next, you will need to insert the encrypted secret into the MongoDB database using Mongo shell or a MongoDB client:
57+
58+
```bash
59+
mongosh mongodb://localhost:27017/secrets_db
60+
```
61+
62+
or if you are using a secure MongoDB instance with authentication:
63+
64+
```bash
65+
mongosh mongodb://localhost:27017/secrets_db -u admin -p password --authenticationDatabase admin
66+
```
67+
68+
Press `Enter` to connect to the database, then run the following command to insert the secret, replacing the
69+
`secretname` with the name of your secret and the `ciphertext` with the actual ciphertext generated by the Ignition
70+
REST API:
71+
72+
```javascript
73+
secrets_db> db.mycollection.insertOne({
74+
"name": "secretname",
75+
"ciphertext": {
76+
"ciphertext" : "NhkoviQxLsUZ2g",
77+
"encrypted_key" : "fYxDhnE_nKXiWGwGBJVaEWhojeg7duY3Y3G4dF89sKdjuf5iiX2nKw",
78+
"iv" : "TTGQPncN-rlf70Bq",
79+
"protected" : "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIiwiaWF0IjoxNzU1NjM0NDg3LCJ6aXAiOiJERUYifQ",
80+
"tag" : "sMU9-vhCyWHxLCH190eQ3A"
81+
}
82+
})
83+
```

secret-provider/pom.xml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.inductiveautomation.ignition.examples</groupId>
8+
<artifactId>secret-provider</artifactId>
9+
<packaging>pom</packaging>
10+
<version>1.3.0-SNAPSHOT</version>
11+
12+
<modules>
13+
<module>secret-provider-build</module>
14+
<module>secret-provider-gateway</module>
15+
</modules>
16+
17+
<properties>
18+
<ignition-platform-version>8.3.0-rc1</ignition-platform-version>
19+
<ignition-sdk-version>${ignition-platform-version}</ignition-sdk-version>
20+
<module-name>MongoDB Secret Provider Example</module-name>
21+
<module-description>Adds a secret provider backed by MongoDB to Ignition.</module-description>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
</properties>
25+
26+
<pluginRepositories>
27+
<pluginRepository>
28+
<id>releases</id>
29+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-releases</url>
30+
<releases>
31+
<enabled>true</enabled>
32+
<updatePolicy>always</updatePolicy>
33+
</releases>
34+
<snapshots>
35+
<enabled>false</enabled>
36+
</snapshots>
37+
</pluginRepository>
38+
</pluginRepositories>
39+
40+
<repositories>
41+
<repository>
42+
<id>ia-releases</id>
43+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-releases</url>
44+
<snapshots>
45+
<enabled>false</enabled>
46+
</snapshots>
47+
<releases>
48+
<enabled>true</enabled>
49+
<updatePolicy>always</updatePolicy>
50+
</releases>
51+
</repository>
52+
53+
<repository>
54+
<id>ia-snapshots</id>
55+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-snapshots</url>
56+
<snapshots>
57+
<enabled>true</enabled>
58+
<updatePolicy>always</updatePolicy>
59+
</snapshots>
60+
<releases>
61+
<enabled>false</enabled>
62+
</releases>
63+
</repository>
64+
65+
<repository>
66+
<id>ia-thirdparty</id>
67+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-thirdparty</url>
68+
<releases>
69+
<enabled>true</enabled>
70+
<updatePolicy>always</updatePolicy>
71+
</releases>
72+
<snapshots>
73+
<enabled>false</enabled>
74+
</snapshots>
75+
</repository>
76+
77+
<repository>
78+
<id>ia-beta</id>
79+
<url>https://nexus.inductiveautomation.com/repository/inductiveautomation-beta</url>
80+
</repository>
81+
</repositories>
82+
83+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<title>Module User Manual</title>
6+
</head>
7+
<body>
8+
<h1>Instructions</h1>
9+
<p>This is the root of my module's user manual.</p>
10+
</body>
11+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<title>Module License</title>
6+
</head>
7+
<body>
8+
<h1>Example License</h1>
9+
<p>This is the license for my module. You must agree to it.</p>
10+
</body>
11+
</html>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>com.inductiveautomation.ignition.examples</groupId>
8+
<artifactId>secret-provider</artifactId>
9+
<version>1.3.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>secret-provider-build</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>com.inductiveautomation.ignition.examples</groupId>
17+
<artifactId>secret-provider-gateway</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
</dependencies>
21+
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>com.inductiveautomation.ignitionsdk</groupId>
26+
<artifactId>ignition-maven-plugin</artifactId>
27+
<version>1.2.0</version>
28+
29+
<executions>
30+
<execution>
31+
<phase>package</phase>
32+
<goals>
33+
<goal>modl</goal>
34+
</goals>
35+
</execution>
36+
</executions>
37+
38+
<configuration>
39+
<projectScopes>
40+
<projectScope>
41+
<name>secret-provider-gateway</name>
42+
<scope>G</scope>
43+
</projectScope>
44+
</projectScopes>
45+
46+
<moduleId>com.inductiveautomation.ignition.examples.secret-provider</moduleId>
47+
<moduleName>${module-name}</moduleName>
48+
<moduleDescription>${module-description}</moduleDescription>
49+
<moduleVersion>${project.version}</moduleVersion>
50+
<requiredIgnitionVersion>${ignition-platform-version}</requiredIgnitionVersion>
51+
<licenseFile>license.html</licenseFile>
52+
53+
<hooks>
54+
<hook>
55+
<scope>G</scope>
56+
<hookClass>com.inductiveautomation.ignition.examples.secretprovider.mongodb.GatewayHook</hookClass>
57+
</hook>
58+
</hooks>
59+
</configuration>
60+
</plugin>
61+
</plugins>
62+
</build>
63+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>com.inductiveautomation.ignition.examples</groupId>
9+
<artifactId>secret-provider</artifactId>
10+
<version>1.3.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>secret-provider-gateway</artifactId>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>com.inductiveautomation.ignitionsdk</groupId>
18+
<artifactId>ignition-common</artifactId>
19+
<version>${ignition-sdk-version}</version>
20+
<type>pom</type>
21+
<scope>provided</scope>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>com.inductiveautomation.ignitionsdk</groupId>
26+
<artifactId>gateway-api</artifactId>
27+
<version>${ignition-sdk-version}</version>
28+
<type>pom</type>
29+
<scope>provided</scope>
30+
</dependency>
31+
32+
<!-- https://mvnrepository.com/artifact/org.mongodb/mongodb-driver-sync -->
33+
<dependency>
34+
<groupId>org.mongodb</groupId>
35+
<artifactId>mongodb-driver-sync</artifactId>
36+
<version>5.5.1</version>
37+
</dependency>
38+
</dependencies>
39+
40+
<build>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>3.2</version>
46+
<configuration>
47+
<source>17</source>
48+
<target>17</target>
49+
</configuration>
50+
</plugin>
51+
</plugins>
52+
</build>
53+
</project>

0 commit comments

Comments
 (0)