diff --git a/.github/workflows/deletedroplets.yml b/.github/workflows/deletedroplets.yml index 11577278a..e16876d60 100644 --- a/.github/workflows/deletedroplets.yml +++ b/.github/workflows/deletedroplets.yml @@ -12,7 +12,7 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'success' }} steps: - name: get logs - uses: dawidd6/action-download-artifact@v6 + uses: dawidd6/action-download-artifact@v7 with: run_id: ${{ github.event.workflow_run.id}} if_no_artifact_found: warn @@ -75,7 +75,7 @@ jobs: if: ${{ github.event.workflow_run.conclusion == 'failure' }} steps: - name: get logs - uses: dawidd6/action-download-artifact@v6 + uses: dawidd6/action-download-artifact@v7 with: run_id: ${{ github.event.workflow_run.id}} if_no_artifact_found: warn diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index e32481393..4d94f3045 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -52,8 +52,8 @@ services: - caddy_data:/data - caddy_conf:/config ports: - - "80:80" - - "443:443" + - "$SERVER_HOST:80:80" + - "$SERVER_HOST:443:443" coredns: #network_mode: host diff --git a/controllers/ext_client.go b/controllers/ext_client.go index 874c62576..1c751cc47 100644 --- a/controllers/ext_client.go +++ b/controllers/ext_client.go @@ -490,6 +490,13 @@ func createExtClient(w http.ResponseWriter, r *http.Request) { if err == nil { // check if parent network default ACL is enabled (yes) or not (no) extclient.Enabled = parentNetwork.DefaultACL == "yes" } + extclient.Os = customExtClient.Os + extclient.DeviceName = customExtClient.DeviceName + if customExtClient.IsAlreadyConnectedToInetGw { + slog.Warn("RAC/Client is already connected to internet gateway. this may mask their real IP address", "client IP", customExtClient.PublicEndpoint) + } + extclient.PublicEndpoint = customExtClient.PublicEndpoint + extclient.Country = customExtClient.Country if err = logic.CreateExtClient(&extclient); err != nil { slog.Error( diff --git a/controllers/node.go b/controllers/node.go index d7f2e2569..e96e2a443 100644 --- a/controllers/node.go +++ b/controllers/node.go @@ -679,6 +679,11 @@ func updateNode(w http.ResponseWriter, r *http.Request) { logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) return } + err = logic.ValidateNodeIp(¤tNode, &newData) + if err != nil { + logic.ReturnErrorResponse(w, r, logic.FormatError(err, "badrequest")) + return + } if !servercfg.IsPro { newData.AdditionalRagIps = []string{} } diff --git a/go.mod b/go.mod index 732158b26..800e2bd09 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,8 @@ go 1.23 require ( github.com/eclipse/paho.mqtt.golang v1.4.3 - github.com/go-playground/validator/v10 v10.22.1 - github.com/golang-jwt/jwt/v4 v4.5.0 + github.com/go-playground/validator/v10 v10.23.0 + github.com/golang-jwt/jwt/v4 v4.5.1 github.com/google/uuid v1.6.0 github.com/gorilla/handlers v1.5.2 github.com/gorilla/mux v1.8.1 @@ -17,11 +17,11 @@ require ( github.com/stretchr/testify v1.9.0 github.com/txn2/txeh v1.5.5 go.uber.org/automaxprocs v1.6.0 - golang.org/x/crypto v0.28.0 + golang.org/x/crypto v0.29.0 golang.org/x/net v0.27.0 // indirect - golang.org/x/oauth2 v0.23.0 - golang.org/x/sys v0.26.0 // indirect - golang.org/x/text v0.19.0 // indirect + golang.org/x/oauth2 v0.24.0 + golang.org/x/sys v0.27.0 // indirect + golang.org/x/text v0.20.0 // indirect golang.zx2c4.com/wireguard/wgctrl v0.0.0-20221104135756-97bc4ad4a1cb gopkg.in/yaml.v3 v3.0.1 ) @@ -68,5 +68,5 @@ require ( github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sync v0.8.0 // indirect + golang.org/x/sync v0.9.0 // indirect ) diff --git a/go.sum b/go.sum index 57d374621..6cd338965 100644 --- a/go.sum +++ b/go.sum @@ -25,10 +25,10 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= -github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o= +github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= @@ -99,8 +99,8 @@ go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwE golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= -golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= -golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= +golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= +golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc= golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -112,13 +112,13 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= -golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= -golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= +golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -127,8 +127,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo= -golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= +golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -140,8 +140,8 @@ golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= -golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= +golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/logic/nodes.go b/logic/nodes.go index d4f9df087..c3f19aec6 100644 --- a/logic/nodes.go +++ b/logic/nodes.go @@ -224,6 +224,16 @@ func UpdateNode(currentNode *models.Node, newNode *models.Node) error { if servercfg.CacheEnabled() { storeNodeInCache(*newNode) storeNodeInNetworkCache(*newNode, newNode.Network) + if _, ok := allocatedIpMap[newNode.Network]; ok { + if newNode.Address.IP != nil && !newNode.Address.IP.Equal(currentNode.Address.IP) { + AddIpToAllocatedIpMap(newNode.Network, newNode.Address.IP) + RemoveIpFromAllocatedIpMap(currentNode.Network, currentNode.Address.IP.String()) + } + if newNode.Address6.IP != nil && !newNode.Address6.IP.Equal(currentNode.Address6.IP) { + AddIpToAllocatedIpMap(newNode.Network, newNode.Address6.IP) + RemoveIpFromAllocatedIpMap(currentNode.Network, currentNode.Address6.IP.String()) + } + } } return nil } @@ -712,6 +722,26 @@ func ValidateParams(nodeid, netid string) (models.Node, error) { return node, nil } +func ValidateNodeIp(currentNode *models.Node, newNode *models.ApiNode) error { + + if currentNode.Address.IP != nil && currentNode.Address.String() != newNode.Address { + newIp, _, _ := net.ParseCIDR(newNode.Address) + ipAllocated := allocatedIpMap[currentNode.Network] + if _, ok := ipAllocated[newIp.String()]; ok { + return errors.New("ip specified is already allocated: " + newNode.Address) + } + } + if currentNode.Address6.IP != nil && currentNode.Address6.String() != newNode.Address6 { + newIp, _, _ := net.ParseCIDR(newNode.Address6) + ipAllocated := allocatedIpMap[currentNode.Network] + if _, ok := ipAllocated[newIp.String()]; ok { + return errors.New("ip specified is already allocated: " + newNode.Address6) + } + } + + return nil +} + func ValidateEgressRange(gateway models.EgressGatewayRequest) error { network, err := GetNetworkSettings(gateway.NetID) if err != nil { diff --git a/models/extclient.go b/models/extclient.go index a6214c34a..cbccc5dd3 100644 --- a/models/extclient.go +++ b/models/extclient.go @@ -21,20 +21,29 @@ type ExtClient struct { PostUp string `json:"postup" bson:"postup"` PostDown string `json:"postdown" bson:"postdown"` Tags map[TagID]struct{} `json:"tags"` + Os string `json:"os"` + DeviceName string `json:"device_name"` + PublicEndpoint string `json:"public_endpoint"` + Country string `json:"country"` } // CustomExtClient - struct for CustomExtClient params type CustomExtClient struct { - ClientID string `json:"clientid,omitempty"` - PublicKey string `json:"publickey,omitempty"` - DNS string `json:"dns,omitempty"` - ExtraAllowedIPs []string `json:"extraallowedips,omitempty"` - Enabled bool `json:"enabled,omitempty"` - DeniedACLs map[string]struct{} `json:"deniednodeacls" bson:"acls,omitempty"` - RemoteAccessClientID string `json:"remote_access_client_id"` // unique ID (MAC address) of RAC machine - PostUp string `json:"postup" bson:"postup" validate:"max=1024"` - PostDown string `json:"postdown" bson:"postdown" validate:"max=1024"` - Tags map[TagID]struct{} `json:"tags"` + ClientID string `json:"clientid,omitempty"` + PublicKey string `json:"publickey,omitempty"` + DNS string `json:"dns,omitempty"` + ExtraAllowedIPs []string `json:"extraallowedips,omitempty"` + Enabled bool `json:"enabled,omitempty"` + DeniedACLs map[string]struct{} `json:"deniednodeacls" bson:"acls,omitempty"` + RemoteAccessClientID string `json:"remote_access_client_id"` // unique ID (MAC address) of RAC machine + PostUp string `json:"postup" bson:"postup" validate:"max=1024"` + PostDown string `json:"postdown" bson:"postdown" validate:"max=1024"` + Tags map[TagID]struct{} `json:"tags"` + Os string `json:"os"` + DeviceName string `json:"device_name"` + IsAlreadyConnectedToInetGw bool `json:"is_already_connected_to_inet_gw"` + PublicEndpoint string `json:"public_endpoint"` + Country string `json:"country"` } func (ext *ExtClient) ConvertToStaticNode() Node { diff --git a/scripts/nm-quick.sh b/scripts/nm-quick.sh index 232eb3f02..dcd6398ef 100755 --- a/scripts/nm-quick.sh +++ b/scripts/nm-quick.sh @@ -127,7 +127,7 @@ setup_netclient() { ./netclient install echo "Register token: $TOKEN" sleep 2 - netclient join -t $TOKEN + netclient join -t $TOKEN --static-port -p 443 echo "waiting for netclient to become available" local found=false @@ -251,10 +251,8 @@ save_config() { ( if [ "$INSTALL_TYPE" = "pro" ]; then save_config_item NETMAKER_TENANT_ID "$NETMAKER_TENANT_ID" save_config_item LICENSE_KEY "$LICENSE_KEY" - if [ "$UPGRADE_FLAG" = "yes" ];then - save_config_item METRICS_EXPORTER "on" - save_config_item PROMETHEUS "on" - fi + save_config_item METRICS_EXPORTER "on" + save_config_item PROMETHEUS "on" save_config_item SERVER_IMAGE_TAG "$IMAGE_TAG-ee" else save_config_item METRICS_EXPORTER "off" @@ -559,7 +557,7 @@ set_install_vars() { echo " api.$NETMAKER_BASE_DOMAIN" echo " broker.$NETMAKER_BASE_DOMAIN" - if [ "$UPGRADE_FLAG" = "yes" ]; then + if [ "$INSTALL_TYPE" = "pro" ]; then echo " prometheus.$NETMAKER_BASE_DOMAIN" echo " netmaker-exporter.$NETMAKER_BASE_DOMAIN" echo " grafana.$NETMAKER_BASE_DOMAIN" @@ -632,13 +630,12 @@ install_netmaker() { if [ "$INSTALL_TYPE" = "pro" ]; then local COMPOSE_OVERRIDE_URL="$BASE_URL/compose/docker-compose.pro.yml" local CADDY_URL="$BASE_URL/docker/Caddyfile-pro" - fi - wget -qO "$SCRIPT_DIR"/docker-compose.yml $COMPOSE_URL - if [ "$UPGRADE_FLAG" = "yes" ]; then wget -qO "$SCRIPT_DIR"/docker-compose.override.yml $COMPOSE_OVERRIDE_URL elif [ -a "$SCRIPT_DIR"/docker-compose.override.yml ]; then rm -f "$SCRIPT_DIR"/docker-compose.override.yml fi + wget -qO "$SCRIPT_DIR"/docker-compose.yml $COMPOSE_URL + wget -qO "$SCRIPT_DIR"/Caddyfile "$CADDY_URL" wget -qO "$SCRIPT_DIR"/netmaker.default.env "$BASE_URL/scripts/netmaker.default.env" wget -qO "$SCRIPT_DIR"/mosquitto.conf "$BASE_URL/docker/mosquitto.conf"