Skip to content

Commit

Permalink
Merge pull request #165 from TehMuffinMoo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
TehMuffinMoo authored Sep 6, 2024
2 parents ef2e39d + e4eaab2 commit abae025
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
$Filters += "t1=$EndEpoch"
}
if ($Query) {
$Filters += "qname=$Name"
$Filters += "qname=$Query"
}
if ($IP) {
$Filters += "qip=$IP"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
$dataTypes += (Build-BulkExportTypes -Types 'atcapi').DataType ## Threat Defense Types
}
if ($Bootstrap -or $BackupAll) {
$dataTypes += (Build-BulkExportTypes -Types 'bootstrap').DataType | Out-Null ## Bootstrap / Host Config
$dataTypes += (Build-BulkExportTypes -Types 'bootstrap').DataType ## Bootstrap / Host Config
}
if ($B1Hosts -or $BackupAll) {
$dataTypes += (Build-BulkExportTypes -Types 'hosts').DataType ## B1 Host Config / Host Config
Expand Down
31 changes: 19 additions & 12 deletions Modules/ibPS/Functions/BloxOne/Private/Get-B1CSPAPIKey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
Write-Colour "See the following link for more information: ","`nhttps://ibps.readthedocs.io/en/latest/#authentication-api-key" -Colour Cyan,Magenta
return $null
}
} elseif ($ENV:IBPSB1APIKEY) {
$ApiKey = $ENV:IBPSB1APIKEY
$PlainText = $true
} else {
$ApiKey = $ENV:B1APIKey
}
Expand All @@ -41,19 +44,23 @@
Write-Colour "See the following link for more information: ","`nhttps://ibps.readthedocs.io/en/latest/#authentication-api-key" -Colour Cyan,Magenta
break
} else {
try {
$Bytes = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($ApiKey)) | ConvertTo-SecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Bytes)
$B1APIKey = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($BSTR)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
if ($B1APIKey) {
return $B1APIKey
if (!$PlainText) {
try {
$Bytes = [System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($ApiKey)) | ConvertTo-SecureString
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Bytes)
$B1APIKey = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($BSTR)
[Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR)
if ($B1APIKey) {
return $B1APIKey
}
} catch {
Write-Colour 'Error. Unable to decode the API Key. Please set the Global API Key again using: ','Set-ibPSConfiguration -CSPAPIKey <apikey>', ' or create a new connection profile.' -Colour Red,Green,Red
Write-Colour 'If you have recently upgraded from a version older than ','v1.9.5.0',', you will need to update your API Key.' -Colour Yellow,Red,Yellow
Write-Colour "See the following link for more information: ","`nhttps://ibps.readthedocs.io/en/latest/#authentication-api-key" -Colour Cyan,Magenta
break
}
} catch {
Write-Colour 'Error. Unable to decode the API Key. Please set the Global API Key again using: ','Set-ibPSConfiguration -CSPAPIKey <apikey>', ' or create a new connection profile.' -Colour Red,Green,Red
Write-Colour 'If you have recently upgraded from a version older than ','v1.9.5.0',', you will need to update your API Key.' -Colour Yellow,Red,Yellow
Write-Colour "See the following link for more information: ","`nhttps://ibps.readthedocs.io/en/latest/#authentication-api-key" -Colour Cyan,Magenta
break
} else {
return $ApiKey
}
}
}
4 changes: 2 additions & 2 deletions Modules/ibPS/Functions/BloxOne/Private/Invoke-CSP.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@

if ($APIKey) {
$B1ApiKey = "Token $($APIKey)"
} elseif ($ENV:B1APIKey) {
## Get Stored API Key (Legacy)
} elseif ($ENV:B1APIKey -or $ENV:IBPSB1APIKEY) {
## Get Stored Global API Key or Plain-Text API Key from ENV
$B1ApiKey = "Token $(Get-B1CSPAPIKey)"
} elseif ($ProfileName) {
## Get API Key from Selected Connection Profile
Expand Down
8 changes: 4 additions & 4 deletions Modules/ibPS/Functions/Misc/Get-ibPSConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@

$CurrentConfig = [PSCustomObject]@{
"CSP Url" = $(if ($ENV:B1CSPUrl) {$ENV:B1CSPUrl} elseif ($BCP = Get-B1ConnectionProfile) {$BCP.'CSP URL'} else {'https://csp.infoblox.com'})
"CSP API User" = $(if ($ENV:B1APIKey) {(Get-B1CSPCurrentUser).name} elseif ($BCP = Get-B1ConnectionProfile) {$BCP.'CSP User'} else {'API Key Not Set'})
"CSP Account" = $(if ($ENV:B1APIKey) {(Get-B1CSPCurrentUser -Account).name} elseif ($BCP = Get-B1ConnectionProfile) {$BCP.'CSP Account'} else {'API Key Not Set'})
"CSP API Key" = $(if ($ENV:B1APIKey) {if ($IncludeAPIKey) {Get-B1CSPAPIKey} else { "********" }} elseif ($BCP = Get-B1ConnectionProfile -IncludeAPIKey:$IncludeAPIKey) {$BCP.'API Key'} else {'API Key Not Set'})
"BloxOne Profile" = $(if ($ENV:B1APIKey) { 'The Global API Key is overriding the Active profile' } elseif ($BCP = Get-B1ConnectionProfile) { $BCP.Name } else { 'None' })
"CSP API User" = $(if ($ENV:B1APIKey -or $ENV:IBPSB1APIKEY) {(Get-B1CSPCurrentUser).name} elseif ($BCP = Get-B1ConnectionProfile) {$BCP.'CSP User'} else {'API Key Not Set'})
"CSP Account" = $(if ($ENV:B1APIKey -or $ENV:IBPSB1APIKEY) {(Get-B1CSPCurrentUser -Account).name} elseif ($BCP = Get-B1ConnectionProfile) {$BCP.'CSP Account'} else {'API Key Not Set'})
"CSP API Key" = $(if ($ENV:B1APIKey -or $ENV:IBPSB1APIKEY) {if ($IncludeAPIKey) {Get-B1CSPAPIKey} else { "********" }} elseif ($BCP = Get-B1ConnectionProfile -IncludeAPIKey:$IncludeAPIKey) {$BCP.'API Key'} else {'API Key Not Set'})
"BloxOne Profile" = $(if ($ENV:B1APIKey) { 'The Global API Key is overriding the Active profile' } elseif ($ENV:IBPSB1APIKEY) { 'Environment' } elseif ($BCP = Get-B1ConnectionProfile) { $BCP.Name } else { 'None' })
"NIOS Profile" = $(if ($NCP = Get-NIOSConnectionProfile) { $NCP.Name} else { 'None' })
"DoH Server" = $(if ($ENV:IBPSDoH) {$ENV:IBPSDoH} else { 'Not Set' })
"ibPS Version" = $ibPSModule.Version.ToString()
Expand Down
2 changes: 1 addition & 1 deletion Modules/ibPS/Functions/Misc/Misc.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ function Build-BulkExportTypes {
)

if (-not $Script:B1BulkExportTypes) {
$Script:B1BulkExportTypes = Invoke-CSP -Method GET -Uri 'https://csp.infoblox.com/bulk/v1/types' | Select-Object -ExpandProperty results
$Script:B1BulkExportTypes = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/bulk/v1/types" | Select-Object -ExpandProperty results
}

$ReturnProperties = @{
Expand Down
6 changes: 3 additions & 3 deletions Modules/ibPS/Functions/Misc/build.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"Build": "0",
"SHA": "c9dea9d3d107b002ba55d6d10d9091c5d4855f01",
"Branch": "main"
"Build": 4,
"SHA": "f90b881b4fd45cbff53a417f19f9886c4024aa07",
"Branch": "dev"
}
12 changes: 3 additions & 9 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
- Fix bug with BloxOne Schema caching
- Add `Get-B1ThreatActor` function to enable querying Threat Actors from TIDE and additionally return related IOCs.
- Add `Get-NIOSFileOp` function for receiving files from NIOS
- Rename `Get-B1Export` to `Receive-B1Export`
- Add new `Get-B1Export` convenience function to query a list of Bulk Operations with type Export
- Add new `Get-B1Import` convenience function to query a list of Bulk Operations with type Import
- Add new `-CaseInsensitive` parameter when using supported `Get-` functions. The default is now case-insensitive searching, to fix some inconsistent query experiences. [More information here](https://ibps.readthedocs.io/en/dev/#common-parameters).
- Add new `Get-B1CustomRedirect` function
- Fix bug with `New-B1LookalikeTarget`
- Fix bug when using `-Query` parameter on `Get-B1DNSEvent`
- Fix bug when using `-Bootstrap` parameter on `Start-B1Export`
- Add the ability to pass the API Key via Environment Variables. [More information here](https://ibps.readthedocs.io/en/main/#environment-variable).
10 changes: 10 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ Alternatively, you can simply store your API Key for the current powershell sess
Set-ibPSConfiguration -CSPAPIKey "<ApiKeyFromCSP>"
```

##### Environment Variable
You can additionally pass the API Key via an Environment Variable. This will pass in the credentials as clear text, but can be used for non-persistent transactions such as leveraging ibPS via Ansible .
```bash
export IBPSB1APIKEY='<ApiKeyFromCSP>'
```

```powershell
$ENV:IBPSB1APIKEY = '<ApiKeyFromCSP>'
```

#### Managing multiple BloxOne Accounts
When managing more than one account, you can use the Profiles configuration. Configuration Profiles enable you to save API keys for multiple accounts, and easily switch between them.

Expand Down

0 comments on commit abae025

Please sign in to comment.