cedws/iapc
GitHub: cedws/iapc
Google Cloud Identity-Aware Proxy 的替代客户端和 Go 库,通过 WebSocket 隧道连接实现对云端实例和 VPC 内网主机的安全访问。
Stars: 18 | Forks: 3
# iapc
Google Cloud Identity-Aware Proxy 的替代客户端和 Go 库。它基于 [gartnera/gcloud](https://github.com/gartnera/gcloud) 中的实现以及官方 gcloud 源代码。它旨在暴露更多功能并具有更好的性能。值得一提的是,IAP 使用的是在[此处](https://chromium.googlesource.com/apps/libapps/+/HEAD/nassh/docs/relay-protocol.md#corp-relay-v4)记录的 SSH Relay v4 协议的略微修改版本。
```
flowchart LR
subgraph Client
Client1[Client 1] --- IAPC
Client2[Client 2] --- IAPC
end
subgraph Google Cloud
IAPC -- WebSocket --> IAP(Identity-Aware Proxy)
IAP --- Instance
IAP --- HostIP["Host (requires BeyondCorp)"]
end
```
## 安装
### Brew
```
brew install cedws/tap/iapc
```
### Scoop
```
scoop bucket add cedws https://github.com/cedws/scoop-bucket.git
scoop install iapc
```
### Go
```
go install github.com/cedws/iapc@latest
```
## CLI
CLI 需要获取应用默认凭据 (ADC) 以通过代理进行身份验证,因此请确保您已登录。
```
$ gcloud auth login --update-adc
```
以下是如何在默认端口 22 上创建到实例的隧道的示例。
```
$ iapc to-instance prod-1 --project analog-figure-330721 --zone europe-west2-a
```
以下是如何在 VPC 中创建到私有 IP 或 FQDN 的隧道的示例。这**需要** BeyondCorp Enterprise 和 TCP Destination Group。
```
$ iapc to-host 192.168.0.1 --project analog-figure-330721 --region europe-west2 --network prod --dest-group prod
```
## 示例代码
此代码示例将 stdin/stdout 连接到实例上的 8080 端口 TCP 连接。在实例上运行 `nc -l 0.0.0.0 8080` 以观察双向通信。
```
package main
import (
"context"
"io"
"log"
"os"
"github.com/cedws/iapc/iap"
"golang.org/x/oauth2/google"
)
func main() {
tokenSource, err := google.DefaultTokenSource(context.Background())
if err != nil {
log.Fatal(err)
}
opts := []iap.DialOption{
iap.WithProject("analog-figure-330721"),
iap.WithInstance("prod-1", "europe-west2-a", "nic0"),
iap.WithPort("8080"),
iap.WithTokenSource(&tokenSource),
}
tun, err := iap.Dial(context.Background(), opts...)
if err != nil {
log.Fatal(err)
}
defer tun.Close()
log.Println("Connected!")
go io.Copy(tun, os.Stdout)
io.Copy(os.Stdin, tun)
}
```
## 许可证
本项目根据您的选择获得 MIT 或 GPLv3 的许可。
标签:EVTX分析, Golang, Google Cloud, SOC Prime, SSH隧道, 安全合规, 安全编程, 开发工具, 日志审计, 网络代理, 身份感知代理