You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🌟 [Major]: Replace SecretStore with custom Sodium based vault (#76)
## Description
🌟 [Major]: All current stored contexts will not be accessible from the
Context module after updating.
This pull request includes significant changes to the context management
system, mainly focusing on transitioning from the
`Microsoft.PowerShell.SecretManagement` module to a local implementation
and
using `Sodium` for encryption of secrets. The changes impact multiple
functions, including context management and configuration.
### Transition to `Sodium` module:
*
[`src/functions/private/Import-Context.ps1`](diffhunk://#diff-fc68944c31a324729fbd1eff057b48bee52d49c57145f1fa3ac7eef0dc092b10L1-R1):
Updated the module requirement to `Sodium` and modified the context
import logic to use JSON files and Sodium encryption.
[[1]](diffhunk://#diff-fc68944c31a324729fbd1eff057b48bee52d49c57145f1fa3ac7eef0dc092b10L1-R1)
[[2]](diffhunk://#diff-fc68944c31a324729fbd1eff057b48bee52d49c57145f1fa3ac7eef0dc092b10L30-L38)
*
[`src/functions/private/Set-ContextVault.ps1`](diffhunk://#diff-406313c23db28018a899056d564dcfc471e582e673440c9659a2278316a03673L1-R18):
Changed the module requirement to `Sodium` and updated the vault
initialization logic to use Sodium key pairs instead of SecretStore.
[[1]](diffhunk://#diff-406313c23db28018a899056d564dcfc471e582e673440c9659a2278316a03673L1-R18)
[[2]](diffhunk://#diff-406313c23db28018a899056d564dcfc471e582e673440c9659a2278316a03673L56-L96)
*
[`src/functions/public/Set-Context.ps1`](diffhunk://#diff-d12895be2e58b33d275f1d10ec54bd8ee0b555bef81f53d6e39ca1722ea58f44L1-R1):
Updated the module requirement to `Sodium` and modified the context
setting logic to use Sodium encryption and JSON files.
[[1]](diffhunk://#diff-d12895be2e58b33d275f1d10ec54bd8ee0b555bef81f53d6e39ca1722ea58f44L1-R1)
[[2]](diffhunk://#diff-d12895be2e58b33d275f1d10ec54bd8ee0b555bef81f53d6e39ca1722ea58f44L51-R102)
### Configuration changes:
*
[`src/variables/private/Config.ps1`](diffhunk://#diff-24f682ffe9ba06c3a7c6620f5c550ddc9eac8bdfb1aefe07961c41cf1a5e9552L2-R6):
Updated the configuration to include new properties for vault path, seed
shard path, and keys.
*
[`src/variables/private/Contexts.ps1`](diffhunk://#diff-b43b49765b90168517446908d901969f395835561822625c504c8e5ac52e78f1L1-R3):
Changed the context storage to use a concurrent dictionary for
thread-safe operations.
### Function updates:
*
[`src/functions/public/Get-Context.ps1`](diffhunk://#diff-0d7db8bc789bd7b13874d319644d59a93cd442baa4da9f9a20854434d7a2b41aL32-R35):
Simplified the parameter definition for the `Get-Context` function and
updated the logic to retrieve contexts.
[[1]](diffhunk://#diff-0d7db8bc789bd7b13874d319644d59a93cd442baa4da9f9a20854434d7a2b41aL32-R35)
[[2]](diffhunk://#diff-0d7db8bc789bd7b13874d319644d59a93cd442baa4da9f9a20854434d7a2b41aL52-R53)
*
[`src/functions/public/Remove-Context.ps1`](diffhunk://#diff-bb64b18ab5c85e130b2713ff666adbabfafe59137c69eb19b1375d410872fbabL1-R1):
Removed the module requirement for SecretManagement and updated the
context removal logic to handle file-based contexts.
[[1]](diffhunk://#diff-bb64b18ab5c85e130b2713ff666adbabfafe59137c69eb19b1375d410872fbabL1-R1)
[[2]](diffhunk://#diff-bb64b18ab5c85e130b2713ff666adbabfafe59137c69eb19b1375d410872fbabL65-R66)
## Type of change
<!-- Use the check-boxes [x] on the options that are relevant. -->
- [ ] 📖 [Docs]
- [ ] 🪲 [Fix]
- [ ] 🩹 [Patch]
- [ ] ⚠️ [Security fix]
- [ ] 🚀 [Feature]
- [x] 🌟 [Breaking change]
## Checklist
<!-- Use the check-boxes [x] on the options that are relevant. -->
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
This module relies on [Microsoft.PowerShell.SecretManagement](https://github.com/powershell/SecretManagement) and
214
-
[Microsoft.PowerShell.SecretStore](https://github.com/PowerShell/SecretStore). The module automatically installs these modules if they are not
215
-
already installed.
216
-
217
214
## Installation
218
215
219
216
Install the module from the PowerShell Gallery by running the following command:
@@ -230,33 +227,33 @@ Lets have a look at how to use the module to store these types of data in abit m
230
227
231
228
### Module settings
232
229
233
-
To store module data, the module developer can create a context that defines a "namespace" for the module. This context can store settings and secrets
234
-
for the module. A module developer can also create additional contexts for additional settings that share the same lifecycle, like settings
230
+
To store module data, the module developer can create a `Context` that defines a "namespace" for the module. This `Context` can store settings
231
+
for the module. A module developer can also create additional `Contexts` for additional settings that share the same lifecycle, like settings
235
232
associated with a module extension.
236
233
237
-
Let's say we have a module called `GitHub` that needs to store some settings and secrets. The module developer could initialize a context called
238
-
`GitHub` as part of the loading section in the module code. All module configuration could be stored in this context by using the functionality in
239
-
this module. The context for the module is stored in the `SecretVault` as a secret with the name `Context:GitHub`.
234
+
Let's say we have a module called `GitHub` that needs to store some settings. The module developer could initialize a `Context` called
235
+
`GitHub` as part of the loading section in the module code. All module configuration could be stored in this `Context` by using the functionality in
236
+
this module. The context for the module is stored in the `ContextVault` as a `Context` with the ID `GitHub`.
240
237
241
238
### User Configuration
242
239
243
-
To store user data, the module developer can create a new context that defines a "namespace" for the user configuration. So let's say a developer has
240
+
To store user data, the module developer can create a new `Context` that defines a "namespace" for the user configuration. So let's say a developer has
244
241
implemented this for the `GitHub` module, a user would log in using their details. The module would call upon `Context` functionality to create a new
245
-
context under the `GitHub` namespace.
242
+
`Context` under the `GitHub` namespace.
246
243
247
-
Imagine a user called `BobMarley` logs in to the `GitHub` module. The following would exist in the context:
244
+
Imagine a user called `BobMarley` logs in to the `GitHub` module. The following would exist in the `ContextVault`:
248
245
249
-
-`Context:GitHub` containing module configuration, like default user, host, and client ID to use if not otherwise specified.
250
-
-`Context:GitHub/BobMarley` containing user configuration, details about the user, secrets and default values for API calls etc.
246
+
-`GitHub` containing module configuration, like default user, host, and client ID to use if not otherwise specified.
247
+
-`GitHub/BobMarley` containing user configuration, details about the user, secrets and default values for API calls etc.
251
248
252
-
Let's say the person also has another account on `GitHub` called `RastaBlasta`. After logging on with the second account, the following context would
253
-
also exist in the context:
249
+
Let's say the person also has another account on `GitHub` called `LennyKravitz`. After logging on the second account, the following `Context` would
250
+
also exist in the `ContextVault`:
254
251
255
-
-`Context:GitHub/RastaBlasta` containing user configuration, details about the user, secrets and default values for API calls etc.
252
+
-`GitHub/LennyKravitz` containing user configuration, details about the user, secrets and default values for API calls etc.
256
253
257
-
With this the module developer could allow users to set default context, and store a key of the name of that context in the module context. This way
258
-
the module could automatically log in the user to the correct account when the module is loaded. The user could also switch between accounts by
259
-
changing the default context.
254
+
With this the module developer could allow users to set default `Context`, and store a key of the name of that `Context` in the module `Context`. This
255
+
way the module could automatically log in the user to the correct account when the module is loaded. The user could also switch between accounts by
256
+
changing the default `Context`.
260
257
261
258
### Setup for a New Module
262
259
@@ -291,21 +288,21 @@ try {
291
288
2. Add some module configuration -> `$context = Get-Context -ID 'GitHub'` -> Change settings using the returned object and
292
289
then `Set-Context -ID 'GitHub' -Context $context` to store the changes.
293
290
294
-
### Setup for a New Context
291
+
### Setup for a New user context
295
292
296
293
To set up a new context for a user, the following steps should be taken:
297
294
298
-
1. Create a set of integration functions that you can expose to the user and that uses the `Context` module to store user data. Its highly recommended
299
-
to do this so that you as a module developer can create the structure you want for the context, while also giving the user the expected function
295
+
1. Create a set of public integration functions that uses the `Context` module to store user data. Its highly recommended
296
+
to do this so that you as a module developer can create the structure you want for the `Context`, while also giving the user the expected function
300
297
names to interact with the module.
301
298
-`Set-<ModuleName>Context` that uses `Set-Context`.
302
299
-`Get-<ModuleName>Context` that uses `Get-Context`.
303
300
-`Remove-<ModuleName>Context` that uses `Remove-Context`
304
301
305
-
2. Create a new context for the user -> `Set-Context -ID 'GitHub.BobMarley'` -> Context `GitHub/BobMarley` is created.
302
+
2. Create a new `Context` for the user `Connect-GitHub ...` -> `Set-Context -ID 'GitHub.BobMarley'` -> `Context``GitHub/BobMarley` is created.
306
303
3. Add some user configuration -> `$context = Get-Context -ID 'GitHub.BobMarley'` -> Change settings using the returned object and
307
304
then `Set-Context -ID 'GitHub.BobMarley' -Context $context` to store the changes.
308
-
4. Get the user configuration -> `Get-Context -Context 'GitHub/BobMarley'` -> The context object is returned, and you can access the data in it.
305
+
4. Get the user configuration -> `Get-Context -Context 'GitHub/BobMarley'` -> The `Context` object is returned, and you can access the data in it.
309
306
310
307
## Contributing
311
308
@@ -323,6 +320,4 @@ If you do code, we'd love to have your contributions. Please read the [Contribut
-[Overview of the SecretManagement and SecretStore modules | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/utility-modules/secretmanagement/overview?view=ps-modules)
0 commit comments