Skip to content
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

WIP: Add NoPluginManagement, NoAccessManagement config options #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PoshBot/Classes/BotConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class BotConfiguration {

[int]$FormatEnumerationLimitOverride = -1

[bool]$NoPluginManagement = $false

[bool]$NoAccessManagement = $false

[ChannelRule[]]$ChannelRules = @([ChannelRule]::new())

[ApprovalConfiguration]$ApprovalConfiguration = [ApprovalConfiguration]::new()
Expand Down Expand Up @@ -104,6 +108,8 @@ class BotConfiguration {
$bc.AddCommandReactions = $hash.AddCommandReactions
$bc.DisallowDMs = $hash.DisallowDMs
$bc.FormatEnumerationLimitOverride = $hash.FormatEnumerationLimitOverride
$bc.NoPluginManagement = $hash.NoPluginManagement
$bc.NoAccessManagement = $hash.NoAccessManagement
$bc.ChannelRules = $hash.ChannelRules.ForEach({[ChannelRule]::Serialize($_)})
$bc.ApprovalConfiguration = [ApprovalConfiguration]::Serialize($hash.ApprovalConfiguration)
$bc.MiddlewareConfiguration = [MiddlewareConfiguration]::Serialize($hash.MiddlewareConfiguration)
Expand Down Expand Up @@ -140,6 +146,8 @@ class BotConfiguration {
$bc.AddCommandReactions = $DeserializedObject.AddCommandReactions
$bc.DisallowDMs = $DeserializedObject.DisallowDMs
$bc.FormatEnumerationLimitOverride = $DeserializedObject.FormatEnumerationLimitOverride
$bc.NoAccessManagement = $DeserializedObject.NoAccessManagement
$bc.NoPluginManagement = $DeserializedObject.NoPluginManagement
$bc.ChannelRules = $DeserializedObject.ChannelRules.Foreach({[ChannelRule]::Serialize($_)})
$bc.ApprovalConfiguration = [ApprovalConfiguration]::Serialize($DeserializedObject.ApprovalConfiguration)
$bc.MiddlewareConfiguration = [MiddlewareConfiguration]::Serialize($DeserializedObject.MiddlewareConfiguration)
Expand Down
10 changes: 10 additions & 0 deletions PoshBot/Public/New-PoshBotConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ function New-PoshBotConfiguration {
.PARAMETER PostResponseMiddlewareHooks
Array of middleware scriptblocks that will run after command responses have been sent to the backend implementation.
This middleware runs after all processing is complete for a command and is a good spot for additional custom logging.
.PARAMETER NoPluginManagement
Disable plugin management from PoshBot itself
This ensures only the plugins configured at load time can run
.PARAMETER NoAccessManagement
Disable access management from PoshBot itself
This ensures only the RBAC configured at load time are in place
.EXAMPLE
PS C:\> New-PoshBotConfiguration -Name Cherry2000 -AlternateCommandPrefixes @('Cherry', 'Sam')

Expand Down Expand Up @@ -272,6 +278,8 @@ function New-PoshBotConfiguration {
[int]$ApprovalExpireMinutes = 30,
[switch]$DisallowDMs,
[int]$FormatEnumerationLimitOverride = -1,
[bool]$NoPluginManagement = $false,
[bool]$NoAccessManagement = $false,
[hashtable[]]$ApprovalCommandConfigurations = @(),
[hashtable[]]$ChannelRules = @(),
[MiddlewareHook[]]$PreReceiveMiddlewareHooks = @(),
Expand Down Expand Up @@ -307,6 +315,8 @@ function New-PoshBotConfiguration {
$config.ApprovalConfiguration.ExpireMinutes = $ApprovalExpireMinutes
$config.DisallowDMs = ($DisallowDMs -eq $true)
$config.FormatEnumerationLimitOverride = $FormatEnumerationLimitOverride
$config.NoPluginManagement = $NoPluginManagement
$config.NoAccessManagement = $NoAccessManagement
if ($ChannelRules.Count -ge 1) {
$config.ChannelRules = $null
foreach ($item in $ChannelRules) {
Expand Down
13 changes: 12 additions & 1 deletion docker/docker_entrypoint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ $configurationSettings = @{
EnvVariable = 'POSHBOT_FORMAT_ENUMERATION_LIMIT'
DefaultValue = -1
}
NoPluginManagement = @{
EnvVariable = 'POSHBOT_NO_PLUGIN_MANAGEMENT'
DefaultValue = -1
}
NoAccessManagement = @{
EnvVariable = 'POSHBOT_NO_ACCESS_MANAGEMENT'
DefaultValue = -1
}
ConfigDir = @{
EnvVariable = 'POSHBOT_CONF_DIR'
DefaultValue = "$rootDrive/poshbot_data"
Expand Down Expand Up @@ -176,6 +184,8 @@ if (-not (Test-Path -Path $configPSD1)) {
CommandHistoryMaxLogsToKeep = $runtimeSettings.CommandHistoryMaxLogsToKeep
BotAdmins = $runtimeSettings.BotAdmins
CommandPrefix = $runtimeSettings.CommandPrefix
NoPluginManagement = $runtimeSettings.NoPluginManagement
NoAccessManagement = $runtimeSettings.NoAccessManagement
AlternateCommandPrefixes = $runtimeSettings.AlternateCommandPrefixes
AlternateCommandPrefixSeperators = $runtimeSettings.AlternateCommandPrefixSeperators
MuteUnknownCommand = $runTimeSettings.MuteUnknownCommand
Expand Down Expand Up @@ -256,7 +266,8 @@ if (-not (Test-Path -Path $configPSD1)) {
#$pbc.ModuleManifestsToLoad = Get-FromEnv -Name 'POSHBOT_MANIFESTS_TO_LOAD' -Default $pbc.ModuleManifestsToLoad
$pbc.AlternateCommandPrefixSeperators = Get-FromEnv -Name 'POSHBOT_ALT_CMD_PREFIX_SEP' -Default $pbc.AlternateCommandPrefixSeperators
$pbc.SendCommandResponseToPrivate = Get-FromEnv -Name 'POSHBOT_SEND_CMD_RESP_TO_PRIV' -Default $pbc.SendCommandResponseToPrivate

$pbc.NoPluginManagement = Get-FromEnv -Name 'POSHBOT_NO_PLUGIN_MANAGEMENT' -Default $pbc.NoPluginManagement
$pbc.NoAccessManagement = Get-FromEnv -Name 'POSHBOT_NO_ACCESS_MANAGEMENT' -Default $pbc.NoAccessManagement
$slackToken = Get-FromEnv -Name 'SLACK_TOKEN' -Default ''
if (-not [string]::IsNullOrEmpty($slackToken)) {
$pbc.BackendConfiguration = @{
Expand Down