mirror of
https://github.com/freedbygrace/PSOPNSenseAPI.git
synced 2026-07-27 04:09:29 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d5fe842cb7 | |||
| 52a422d6cc | |||
| ccfb37aaac | |||
| 28546595bd |
@@ -6,6 +6,8 @@ This component provides cmdlets for managing Tailscale VPN on OPNSense firewalls
|
||||
|
||||
The Tailscale Integration component allows you to install, configure, and manage Tailscale VPN on OPNSense firewalls. It provides cmdlets for enabling Tailscale, configuring subnet routes, and managing the Tailscale connection.
|
||||
|
||||
The module will automatically install the Tailscale plugin if it doesn't exist, making it easy to set up Tailscale on a new OPNSense firewall.
|
||||
|
||||
## Cmdlets
|
||||
|
||||
### Get-OPNSenseTailscaleStatus
|
||||
@@ -138,6 +140,53 @@ Apply-OPNSenseTailscaleChanges
|
||||
Apply-OPNSenseTailscaleChanges -Force
|
||||
```
|
||||
|
||||
### Connect-OPNSenseTailscale
|
||||
|
||||
Connects to the Tailscale network using an authentication key.
|
||||
|
||||
#### Parameters
|
||||
|
||||
- **AuthKey** - The Tailscale authentication key.
|
||||
- **InstallIfMissing** - Installs the Tailscale plugin if it's not already installed.
|
||||
- **EnableIfDisabled** - Enables Tailscale if it's disabled.
|
||||
- **StartIfStopped** - Starts the Tailscale service if it's stopped.
|
||||
- **SubnetRoutes** - The subnet routes to advertise to Tailscale.
|
||||
- **AdvertiseRoutes** - Whether to advertise routes to Tailscale.
|
||||
- **Force** - Suppresses the confirmation prompt.
|
||||
- **PassThru** - Returns the Tailscale status.
|
||||
|
||||
#### Examples
|
||||
|
||||
```powershell
|
||||
# Connect to Tailscale with an auth key
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456"
|
||||
|
||||
# Connect to Tailscale with automatic installation and enablement
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -InstallIfMissing -EnableIfDisabled -StartIfStopped
|
||||
|
||||
# Connect to Tailscale and advertise subnet routes
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -SubnetRoutes "192.168.1.0/24","10.0.0.0/8" -AdvertiseRoutes
|
||||
```
|
||||
|
||||
### Disconnect-OPNSenseTailscale
|
||||
|
||||
Disconnects from the Tailscale network.
|
||||
|
||||
#### Parameters
|
||||
|
||||
- **Force** - Suppresses the confirmation prompt.
|
||||
- **PassThru** - Returns the Tailscale status.
|
||||
|
||||
#### Examples
|
||||
|
||||
```powershell
|
||||
# Disconnect from Tailscale
|
||||
Disconnect-OPNSenseTailscale
|
||||
|
||||
# Disconnect from Tailscale without confirmation
|
||||
Disconnect-OPNSenseTailscale -Force
|
||||
```
|
||||
|
||||
## Common Scenarios
|
||||
|
||||
### Installing and Configuring Tailscale
|
||||
@@ -159,6 +208,19 @@ Apply-OPNSenseTailscaleChanges -Force
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Simplified Installation and Connection
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Connect to Tailscale with automatic installation and enablement
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -InstallIfMissing -EnableIfDisabled -StartIfStopped -Force
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Configuring Tailscale as a Subnet Router
|
||||
|
||||
```powershell
|
||||
@@ -177,14 +239,8 @@ foreach ($interface in $interfaces) {
|
||||
}
|
||||
}
|
||||
|
||||
# Join the subnets with commas
|
||||
$advertisedRoutes = $subnets -join ","
|
||||
|
||||
# Enable Tailscale with route advertisement
|
||||
Enable-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -AdvertiseRoutes $advertisedRoutes -Force
|
||||
|
||||
# Apply the changes
|
||||
Apply-OPNSenseTailscaleChanges -Force
|
||||
# Connect to Tailscale with subnet route advertisement
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -SubnetRoutes $subnets -AdvertiseRoutes -InstallIfMissing -Force
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
@@ -206,6 +262,26 @@ Apply-OPNSenseTailscaleChanges -Force
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Connecting and Disconnecting from Tailscale
|
||||
|
||||
```powershell
|
||||
# Connect to the OPNSense firewall
|
||||
Connect-OPNSense -Server "https://firewall.example.com" -ApiKey "your_api_key" -ApiSecret "your_api_secret" -SkipCertificateCheck
|
||||
|
||||
# Connect to Tailscale
|
||||
Connect-OPNSenseTailscale -AuthKey "tskey-auth-abcdef123456" -InstallIfMissing -EnableIfDisabled -StartIfStopped -Force
|
||||
|
||||
# Get Tailscale status
|
||||
$status = Get-OPNSenseTailscaleStatus
|
||||
Write-Output "Tailscale Status: $($status.Status)"
|
||||
|
||||
# Disconnect from Tailscale
|
||||
Disconnect-OPNSenseTailscale -Force
|
||||
|
||||
# Disconnect from the firewall
|
||||
Disconnect-OPNSense
|
||||
```
|
||||
|
||||
### Updating Tailscale Routes
|
||||
|
||||
```powershell
|
||||
@@ -253,6 +329,7 @@ Disconnect-OPNSense
|
||||
|
||||
- Tailscale requires the Tailscale plugin to be installed on the OPNSense firewall.
|
||||
- The `Install-OPNSenseTailscale` cmdlet will install the plugin if it's not already installed.
|
||||
- The `Connect-OPNSenseTailscale` cmdlet can automatically install the plugin, enable Tailscale, and start the service with the `-InstallIfMissing`, `-EnableIfDisabled`, and `-StartIfStopped` parameters.
|
||||
- Tailscale authentication keys can be generated from the Tailscale admin console.
|
||||
- Authentication keys are single-use and expire after a short period.
|
||||
- When advertising routes, ensure that the routes are valid and do not overlap with Tailscale's internal routes.
|
||||
@@ -261,3 +338,5 @@ Disconnect-OPNSense
|
||||
- The `ExitNode` option allows other Tailscale nodes to use the OPNSense firewall as an internet gateway.
|
||||
- Changes to Tailscale settings are not applied until you call `Apply-OPNSenseTailscaleChanges`.
|
||||
- Consider using the `-PassThru` parameter when updating Tailscale settings to verify the changes.
|
||||
- The `Connect-OPNSenseTailscale` cmdlet combines multiple steps (installation, enablement, and connection) into a single command.
|
||||
- The `Disconnect-OPNSenseTailscale` cmdlet disconnects from the Tailscale network but does not disable Tailscale.
|
||||
|
||||
@@ -11,6 +11,7 @@ The PSOPNSenseAPI solution is a Visual Studio solution that contains the source
|
||||
The solution contains the following projects:
|
||||
|
||||
- **PSOPNSenseAPI**: The main project containing the PowerShell module code.
|
||||
- **PSOPNSenseAPI.Tests**: The test project containing unit tests for the PowerShell module.
|
||||
|
||||
## Opening the Solution
|
||||
|
||||
@@ -56,19 +57,19 @@ If you encounter issues with the IPNetwork2 library, here are some common troubl
|
||||
|
||||
1. **Check the reference**: Ensure that the IPNetwork2 package is properly referenced in the project file.
|
||||
```xml
|
||||
<PackageReference Include="IPNetwork2" Version="2.6.618" />
|
||||
<PackageReference Include="IPNetwork2" Version="3.1.764" />
|
||||
```
|
||||
|
||||
2. **Verify the namespace**: The correct namespace for IPNetwork2 is `System.Net.IPNetwork`.
|
||||
2. **Verify the namespace**: The correct namespace for IPNetwork2 is `System.Net`.
|
||||
```csharp
|
||||
using System.Net.IPNetwork;
|
||||
using System.Net;
|
||||
```
|
||||
|
||||
3. **Check the class name**: The main class in IPNetwork2 is `IPNetwork`, not `IPNetwork2`.
|
||||
```csharp
|
||||
// Correct usage
|
||||
System.Net.IPNetwork.IPNetwork network = System.Net.IPNetwork.IPNetwork.Parse("192.168.1.0/24");
|
||||
|
||||
System.Net.IPNetwork network = System.Net.IPNetwork.Parse("192.168.1.0/24");
|
||||
|
||||
// Incorrect usage
|
||||
IPNetwork2 network = IPNetwork2.Parse("192.168.1.0/24");
|
||||
```
|
||||
@@ -100,7 +101,7 @@ When adding new features to the solution:
|
||||
2. Implement service classes in the `Services` directory
|
||||
3. Create PowerShell cmdlets in the `Cmdlets` directory
|
||||
4. Update the module manifest (`PSOPNSenseAPI.psd1`) to export the new cmdlets
|
||||
5. Add tests for the new features
|
||||
5. Add tests for the new features in the `PSOPNSenseAPI.Tests` project
|
||||
6. Update documentation
|
||||
|
||||
## Testing
|
||||
@@ -112,9 +113,14 @@ The solution includes unit tests that can be run from Visual Studio using the Te
|
||||
.\build\test.ps1
|
||||
```
|
||||
|
||||
## Continuous Integration
|
||||
## Manual Release Process
|
||||
|
||||
The project uses GitHub Actions for continuous integration. The CI workflow builds and tests the solution on every push to the main branch.
|
||||
The project uses a manual release process. To create a new release:
|
||||
|
||||
1. Update the version in the project file and module manifest
|
||||
2. Build the solution in Release mode
|
||||
3. Create a zip file of the module
|
||||
4. Create a GitHub release with the zip file attached
|
||||
|
||||
## Dependencies
|
||||
|
||||
@@ -123,10 +129,29 @@ The solution has the following dependencies:
|
||||
- PowerShellStandard.Library (5.1.1)
|
||||
- Newtonsoft.Json (13.0.3)
|
||||
- System.Net.Http (4.3.4)
|
||||
- IPNetwork2 (2.6.618)
|
||||
- IPNetwork2 (3.1.764)
|
||||
|
||||
## Notes
|
||||
|
||||
- The solution is configured to target both .NET Framework 4.7.2 and .NET Standard 2.0 to support both Windows PowerShell 5.1 and PowerShell 7+.
|
||||
- The module uses a versioning scheme of `yyyy.MM.dd.HHmm` for releases, which is automatically generated during the build process.
|
||||
- The module uses a versioning scheme of `yyyy.MM.dd.HHmm` for releases.
|
||||
- The solution includes XML documentation comments that are used to generate help content for the PowerShell cmdlets.
|
||||
- The module uses System.Reflection.Assembly::LoadBytes to load DLLs to avoid file lock issues.
|
||||
- DLLs are organized in a lib subfolder for neatness.
|
||||
|
||||
## Module Structure
|
||||
|
||||
The module has the following structure:
|
||||
|
||||
```
|
||||
PSOPNSenseAPI/
|
||||
├── lib/ # DLL files
|
||||
│ ├── Newtonsoft.Json.dll
|
||||
│ ├── PSOPNSenseAPI.dll
|
||||
│ ├── System.Net.IPNetwork.dll
|
||||
│ └── ...
|
||||
├── PSOPNSenseAPI.psd1 # Module manifest
|
||||
└── PSOPNSenseAPI.psm1 # Module script that loads DLLs
|
||||
```
|
||||
|
||||
The PSM1 file uses System.Reflection.Assembly::LoadBytes to load the DLLs from the lib folder, which avoids file lock issues that can occur when PowerShell loads DLLs directly.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@{
|
||||
RootModule = 'PSOPNSenseAPI.psm1'
|
||||
ModuleVersion = '2025.04.14.2306'
|
||||
ModuleVersion = '2025.04.14.2320'
|
||||
GUID = '1f0e4b77-cc7c-4a1e-b45a-d7c51a3c562e'
|
||||
Author = 'PSOPNSenseAPI Contributors'
|
||||
CompanyName = 'PSOPNSenseAPI'
|
||||
|
||||
@@ -7,8 +7,8 @@ $dllFiles = Get-ChildItem -Path $libPath -Filter "*.dll"
|
||||
foreach ($dll in $dllFiles) {
|
||||
try {
|
||||
$dllBytes = [System.IO.File]::ReadAllBytes($dll.FullName)
|
||||
[System.Reflection.Assembly]::Load($dllBytes) | Out-Null
|
||||
Write-Verbose "Loaded assembly: $($dll.Name)"
|
||||
$Null = [System.Reflection.Assembly]::Load($dllBytes)
|
||||
Write-Verbose "Attempting to load assembly: $($dll.FullName)"
|
||||
}
|
||||
catch {
|
||||
Write-Warning "Failed to load assembly $($dll.Name): $_"
|
||||
|
||||
Binary file not shown.
@@ -4,7 +4,7 @@
|
||||
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
|
||||
<AssemblyName>PSOPNSenseAPI</AssemblyName>
|
||||
<RootNamespace>PSOPNSenseAPI</RootNamespace>
|
||||
<Version>2025.04.14.2306</Version>
|
||||
<Version>2025.04.14.2320</Version>
|
||||
<Authors>PSOPNSenseAPI Contributors</Authors>
|
||||
<Company>PSOPNSenseAPI</Company>
|
||||
<Description>PowerShell module for interacting with the OPNSense API to configure firewalls</Description>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
RootModule = 'PSOPNSenseAPI.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '2025.04.14.2306'
|
||||
ModuleVersion = '2025.04.14.2320'
|
||||
|
||||
# Supported PSEditions
|
||||
CompatiblePSEditions = @('Desktop', 'Core')
|
||||
|
||||
Reference in New Issue
Block a user