# VPN Grupy Dealer (Tailscale + nasz Headscale, logowanie Google) — Windows jednym poleceniem. # Strona: https://setup.grupadealer.pl · źródło: grupa-dealer-platform/onboarding · runbook 10. # # PowerShell: irm https://setup.grupadealer.pl/vpn.ps1 | iex # Z opcją: & ([scriptblock]::Create((irm https://setup.grupadealer.pl/vpn.ps1))) -Update (albo -Check, -Version) # Z pliku: & ([scriptblock]::Create((Get-Content -Raw -Encoding UTF8 .\vpn.ps1))) -Check # # -Update preferencje BEZ ponownego logowania + test # -Check tylko sprawdzenie, nic nie zmienia # # Bez uprawnień administratora skrypt sam otwiera nowe okno PowerShell jako administrator (pytanie systemu UAC). # Logowanie wyłącznie przez CLI — w GUI Windows nie ma opcji „Use Custom Login Server” (runbook 10). # DNS: przy --accept-dns Tailscale ustawia regułę NRPT kierującą zapytania do 100.100.100.100 — plików stref nie trzeba; # lista poniżej służy tylko do kontroli. Bez sekretów. Idempotentny. Na końcu „WYNIK: OK” albo „WYNIK: DO POPRAWY”. # Cały kod w bloku wywoływanym od razu, bez `exit` i `param()`: przy `irm | iex` `exit` zamknąłby okno PowerShell. # Windows PowerShell 5.1 — bez `??`, `&&`, operatora trójargumentowego. # # Listę stref i testów przepisuje onboarding/gen-domains.sh (bloki BEGIN/END) — nie edytować ich ręcznie. & { $VERSION = '2026.11.16-ad96a38' if ($VERSION.StartsWith('__')) { $VERSION = 'dev (z repo)' } $Site = 'https://setup.grupadealer.pl' $LoginServer = 'https://headscale.ops.grupadealer.pl' $HelpCh = 'kanał #dcrm-devops na Slacku' $Domains = @( # BEGIN DOMAINS (gen-domains.sh) 'dealercrm.pl' 'gd.internal' 'qa.grupadealer.pl' 'vault.ops.grupadealer.pl' # END DOMAINS ) # nazwa → oczekiwany adres albo nazwa, która ma się rozwiązać na ten sam adres $Tests = @( # BEGIN TESTS (gen-domains.sh: nazwa, oczekiwane) ,@('x.qa.grupadealer.pl', 'nonprod-flow.gd.internal') ,@('grafana.gd.internal', '10.3.161.104') # END TESTS ) $Mode = 'install' foreach ($a in $args) { switch -Regex ([string]$a) { '^-{1,2}check$' { $Mode = 'check'; break } '^-{1,2}update$' { $Mode = 'update'; break } '^-{1,2}version$' { $Mode = 'version'; break } default { Write-Host "Nieznany parametr: $a (dostępne: -Check, -Update, -Version)"; $Mode = 'bad' } } } if ($Mode -eq 'bad') { return } if ($Mode -eq 'version') { Write-Host "vpn.ps1 $VERSION"; return } $S = @{ Err = 0; Planned = 0; Todo = (New-Object System.Collections.Generic.List[string]) } function Ok($m) { Write-Host " OK $m" -ForegroundColor Green } function Info($m) { Write-Host " · $m" } function Plan($m) { Write-Host " ZROBIĘ $m" -ForegroundColor Yellow; $S.Planned += 1 } function Bad($m, $fix) { Write-Host " BŁĄD $m" -ForegroundColor Red $S.Err += 1 if (-not $fix) { $fix = $m } if (-not $S.Todo.Contains($fix)) { $S.Todo.Add($fix) } } function Summary { Write-Host '' if ($S.Err -eq 0) { Write-Host 'WYNIK: OK' -ForegroundColor Green if ($Mode -eq 'check' -and $S.Planned -gt 0) { Write-Host " (tryb -Check: $($S.Planned) zmian do zrobienia — uruchom bez -Check)" } } else { Write-Host "WYNIK: DO POPRAWY ($($S.Err))" -ForegroundColor Red $i = 1 foreach ($t in $S.Todo) { Write-Host " $i. $t"; $i++ } if ($Mode -eq 'check' -and $S.Planned -gt 0) { Write-Host " (tryb -Check: $($S.Planned) zmian nie zostało zrobionych — uruchom bez -Check)" } Write-Host " Pomoc: wklej cały ten wynik (wersja $VERSION) na $HelpCh." } } function Resolve-Ip($name) { $r = Resolve-DnsName -Name $name -Type A -DnsOnly -ErrorAction SilentlyContinue | Where-Object { $_.Type -eq 'A' } | Select-Object -First 1 if ($r) { $r.IPAddress } else { '' } } Write-Host "== VPN Grupa Dealer — Windows (wersja $VERSION, tryb: $Mode)" # 0. uprawnienia administratora: bez nich nowe okno PowerShell jako administrator z tym samym poleceniem $admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $admin -and $Mode -ne 'check') { Info 'potrzebne uprawnienia administratora — otwieram nowe okno PowerShell jako administrator (potwierdź pytanie systemu)' $flag = '' if ($Mode -eq 'update') { $flag = ' -Update' } $cmd = "[Net.ServicePointManager]::SecurityProtocol = 'Tls12'; & ([scriptblock]::Create((Invoke-RestMethod '$Site/vpn.ps1')))$flag" try { Start-Process powershell.exe -Verb RunAs -ArgumentList @('-NoExit', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command', $cmd) -ErrorAction Stop Info 'dalszy ciąg i wynik pojawią się w nowym oknie' } catch { Bad 'nie udało się otworzyć PowerShell jako administrator' 'otwórz PowerShell jako administrator (Start → wpisz powershell → prawy klik → Uruchom jako administrator) i wklej polecenie ponownie' Summary } return } # 1. instalacja $ts = Join-Path $env:ProgramFiles 'Tailscale\tailscale.exe' if (Test-Path $ts) { Ok ('tailscale ' + ((& $ts version) | Select-Object -First 1)) } elseif ($Mode -eq 'update') { Bad 'brak Tailscale' "uruchom bez -Update: irm $Site/vpn.ps1 | iex"; Summary; return } elseif ($Mode -eq 'check') { Plan 'instalacja Tailscale (winget tailscale.tailscale albo MSI z pkgs.tailscale.com)' } else { Info 'instalacja Tailscale…' if (Get-Command winget -ErrorAction SilentlyContinue) { winget install --id tailscale.tailscale -e --silent --accept-source-agreements --accept-package-agreements | Out-Null } if (-not (Test-Path $ts)) { $arch = 'amd64' if ($env:PROCESSOR_ARCHITECTURE -eq 'ARM64') { $arch = 'arm64' } Info "winget niedostępny albo nieudany — instalator MSI z pkgs.tailscale.com ($arch)" $msi = Join-Path $env:TEMP 'tailscale-setup.msi' [Net.ServicePointManager]::SecurityProtocol = 'Tls12' Invoke-WebRequest -UseBasicParsing "https://pkgs.tailscale.com/stable/tailscale-setup-latest-$arch.msi" -OutFile $msi Start-Process msiexec.exe -ArgumentList "/i `"$msi`" /qn" -Wait } if (Test-Path $ts) { Ok 'Tailscale zainstalowany (okno aplikacji Tailscale możesz zamknąć — logowanie robi ten skrypt)' } else { Bad 'instalacja Tailscale nie powiodła się' "pobierz instalator z https://tailscale.com/download/windows, zainstaluj i uruchom to polecenie ponownie"; Summary; return } } $st = $null if (Test-Path $ts) { # 2. usługa $svc = Get-Service -Name Tailscale -ErrorAction SilentlyContinue if ($svc -and $svc.Status -eq 'Running') { Ok 'usługa Tailscale działa' } elseif ($Mode -eq 'check') { Plan 'Start-Service Tailscale' } else { Start-Service Tailscale -ErrorAction SilentlyContinue; Start-Sleep 3 if ((Get-Service -Name Tailscale -ErrorAction SilentlyContinue).Status -eq 'Running') { Ok 'usługa Tailscale uruchomiona' } else { Bad 'usługa Tailscale nie wstała' 'uruchom ponownie komputer i to polecenie'; Summary; return } } # 3. logowanie + preferencje try { $st = (& $ts status --json | Out-String | ConvertFrom-Json) } catch { $st = $null } $prefs = (& $ts debug prefs 2>$null) -join "`n" $ctrl = '' if ($prefs -match '"ControlURL":\s*"([^"]*)"') { $ctrl = $Matches[1] } if ($st -and $st.BackendState -eq 'Running' -and $ctrl -eq $LoginServer) { Ok ('zalogowany (' + ((& $ts ip -4) | Select-Object -First 1) + ')') } elseif ($Mode -eq 'update') { Bad "VPN nie jest zalogowany do $LoginServer" "uruchom bez -Update: irm $Site/vpn.ps1 | iex" } elseif ($Mode -eq 'check') { Plan "logowanie: tailscale up --login-server=$LoginServer --accept-dns --accept-routes" } else { Info 'logowanie: otworzy się przeglądarka — zaloguj się kontem imie.nazwisko@grupadealer.pl (Google)' $upArgs = @('up', "--login-server=$LoginServer", '--accept-dns', '--accept-routes') if ($ctrl -and $ctrl -ne $LoginServer) { $upArgs += '--force-reauth' } $opened = $false & $ts @upArgs 2>&1 | ForEach-Object { $line = "$_" Write-Host " $line" if (-not $opened -and $line -match '(https://\S+)') { Start-Process $Matches[1]; $opened = $true; Write-Host ' · czekam na zalogowanie (Ctrl+C przerywa)…' } } if ($LASTEXITCODE -eq 0) { Ok "zalogowano do $LoginServer" } else { Bad "logowanie nie powiodło się (kod $LASTEXITCODE)" 'uruchom polecenie ponownie i dokończ logowanie w przeglądarce kontem @grupadealer.pl' } try { $st = (& $ts status --json | Out-String | ConvertFrom-Json) } catch { $st = $null } } $prefs = (& $ts debug prefs 2>$null) -join "`n" if ($prefs -match '"CorpDNS":\s*true' -and $prefs -match '"RouteAll":\s*true') { Ok 'preferencje: accept-dns, accept-routes' } elseif ($Mode -eq 'check') { Plan 'tailscale set --accept-dns=true --accept-routes=true' } else { & $ts set --accept-dns=true --accept-routes=true if ($LASTEXITCODE -eq 0) { Ok 'preferencje ustawione: accept-dns, accept-routes' } else { Bad 'nie udało się ustawić preferencji' 'uruchom w PowerShell jako administrator: & "C:\Program Files\Tailscale\tailscale.exe" set --accept-dns=true --accept-routes=true' } } $nrpt = Get-DnsClientNrptPolicy -ErrorAction SilentlyContinue | Where-Object { $_.NameServers -contains '100.100.100.100' } if ($nrpt) { Ok 'NRPT: zapytania kierowane do 100.100.100.100' } else { Info 'brak reguły NRPT na 100.100.100.100 (sprawdzi test)' } Info "strefy kierowane do tailnetu (kontrola): $($Domains.Count)" # 4. konto i uprawnienia (nowe konto = brak dostępu, dopóki DevOps nie doda go do grupy) if ($st -and $st.BackendState -eq 'Running') { $login = '' try { $login = ((& $ts whois --json ((& $ts ip -4) | Select-Object -First 1)) | Out-String | ConvertFrom-Json).UserProfile.LoginName } catch {} if ($login) { Info "konto VPN: $login" } else { $login = 'imie.nazwisko@grupadealer.pl' } $peers = 0 if ($st.Peer) { $peers = @($st.Peer.PSObject.Properties).Count } if ($peers -eq 0) { Bad 'VPN działa, ale konto nie ma jeszcze żadnych uprawnień (nowe konto)' "napisz na ${HelpCh}: „Zalogowałem się do VPN: $login, proszę o dostęp” — DevOps doda konto do grupy; potem nic nie trzeba uruchamiać" } } } # 5. test Write-Host '== Test' Clear-DnsClientCache -ErrorAction SilentlyContinue foreach ($t in $Tests) { $got = Resolve-Ip $t[0] $want = $t[1]; $label = $want if ($want -match '[a-z]') { $wantIp = Resolve-Ip $want if ($wantIp) { $label = "adres ${want}: $wantIp" } else { $label = "adres ${want}: nie rozwiązuje się" } } else { $wantIp = $want } if ($got -and $got -eq $wantIp) { Ok "$($t[0]) → $got" } else { $shown = $got if (-not $shown) { $shown = 'brak odpowiedzi' } Bad "$($t[0]) → $shown (oczekiwane $label)" 'nazwy z sieci firmowej nie rozwiązują się przez VPN — sprawdź, czy VPN jest włączony (ikona Tailscale przy zegarze), i uruchom polecenie ponownie' } } Summary } @args