Skip to content

Commit

Permalink
Merge pull request #546 from gravitl/feature_v0.10.0_refactor
Browse files Browse the repository at this point in the history
Feature v0.10.0 refactor
  • Loading branch information
afeiszli authored Dec 12, 2021
2 parents f7c684b + 0bc3014 commit a412596
Show file tree
Hide file tree
Showing 81 changed files with 2,848 additions and 3,246 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ netclient/netclient-32
netclient/netclient32
netclient/netclient.exe
config/dnsconfig/
winsw.exe
data/
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#first stage - builder
FROM golang:1.15-alpine as builder
FROM golang:1.17-alpine as builder
ARG version
RUN apk add build-base
WORKDIR /app
COPY . .
ENV GO111MODULE=auto

# RUN GOOS=linux CGO_ENABLED=1 go build -tags debug -ldflags="-s -X 'main.version=$version'" -o netmaker main.go
RUN GOOS=linux CGO_ENABLED=1 go build -ldflags="-s -X 'main.version=$version'" -o netmaker main.go
FROM alpine:3.13.6
FROM alpine:3.14.3

# add a c lib
RUN apk add gcompat iptables
# set the working directory
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<p align="center">
<a href="https://github.com/gravitl/netmaker/releases">
<img src="https://img.shields.io/badge/Version-0.9.1-informational?style=flat-square" />
<img src="https://img.shields.io/badge/Version-0.9.2-informational?style=flat-square" />
</a>
<a href="https://hub.docker.com/r/gravitl/netmaker/tags">
<img src="https://img.shields.io/docker/pulls/gravitl/netmaker" />
Expand Down
19 changes: 10 additions & 9 deletions auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"strings"

"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
Expand Down Expand Up @@ -53,7 +54,7 @@ func InitializeAuthProvider() string {
}
var _, err = fetchPassValue(logic.RandomString(64))
if err != nil {
logic.Log(err.Error(), 0)
logger.Log(0, err.Error())
return ""
}
var currentFrontendURL = servercfg.GetFrontendURL()
Expand All @@ -64,10 +65,10 @@ func InitializeAuthProvider() string {
var serverConn = servercfg.GetAPIHost()
if strings.Contains(serverConn, "localhost") || strings.Contains(serverConn, "127.0.0.1") {
serverConn = "http://" + serverConn
logic.Log("localhost OAuth detected, proceeding with insecure http redirect: "+serverConn+")", 1)
logger.Log(1, "localhost OAuth detected, proceeding with insecure http redirect: (", serverConn, ")")
} else {
serverConn = "https://" + serverConn
logic.Log("external OAuth detected, proceeding with https redirect: ("+serverConn+")", 1)
logger.Log(1, "external OAuth detected, proceeding with https redirect: ("+serverConn+")")
}

functions[init_provider].(func(string, string, string))(serverConn+"/api/oauth/callback", authInfo[1], authInfo[2])
Expand Down Expand Up @@ -122,7 +123,7 @@ func IsOauthUser(user *models.User) error {
func addUser(email string) error {
var hasAdmin, err = logic.HasAdmin()
if err != nil {
logic.Log("error checking for existence of admin user during OAuth login for "+email+", user not added", 1)
logger.Log(1, "error checking for existence of admin user during OAuth login for", email, "; user not added")
return err
} // generate random password to adapt to current model
var newPass, fetchErr = fetchPassValue("")
Expand All @@ -135,17 +136,17 @@ func addUser(email string) error {
}
if !hasAdmin { // must be first attempt, create an admin
if newUser, err = logic.CreateAdmin(newUser); err != nil {
logic.Log("error creating admin from user, "+email+", user not added", 1)
logger.Log(1, "error creating admin from user,", email, "; user not added")
} else {
logic.Log("admin created from user, "+email+", was first user added", 0)
logger.Log(1, "admin created from user,", email, "; was first user added")
}
} else { // otherwise add to db as admin..?
// TODO: add ability to add users with preemptive permissions
newUser.IsAdmin = false
if newUser, err = logic.CreateUser(newUser); err != nil {
logic.Log("error creating user, "+email+", user not added", 1)
logger.Log(1, "error creating user,", email, "; user not added")
} else {
logic.Log("user created from, "+email+"", 0)
logger.Log(0, "user created from ", email)
}
}
return nil
Expand Down Expand Up @@ -176,7 +177,7 @@ func fetchPassValue(newValue string) (string, error) {

var b64CurrentValue, b64Err = base64.StdEncoding.DecodeString(newValueHolder.Value)
if b64Err != nil {
logic.Log("could not decode pass", 0)
logger.Log(0, "could not decode pass")
return "", nil
}
return string(b64CurrentValue), nil
Expand Down
7 changes: 4 additions & 3 deletions auth/azure-ad.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"os"

"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
Expand Down Expand Up @@ -56,7 +57,7 @@ func handleAzureCallback(w http.ResponseWriter, r *http.Request) {

var content, err = getAzureUserInfo(r.FormValue("state"), r.FormValue("code"))
if err != nil {
logic.Log("error when getting user info from azure: "+err.Error(), 1)
logger.Log(1, "error when getting user info from azure:", err.Error())
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
return
}
Expand All @@ -78,11 +79,11 @@ func handleAzureCallback(w http.ResponseWriter, r *http.Request) {

var jwt, jwtErr = logic.VerifyAuthRequest(authRequest)
if jwtErr != nil {
logic.Log("could not parse jwt for user "+authRequest.UserName, 1)
logger.Log(1, "could not parse jwt for user", authRequest.UserName)
return
}

logic.Log("completed azure OAuth sigin in for "+content.UserPrincipalName, 1)
logger.Log(1, "completed azure OAuth sigin in for", content.UserPrincipalName)
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?login="+jwt+"&user="+content.UserPrincipalName, http.StatusPermanentRedirect)
}

Expand Down
7 changes: 4 additions & 3 deletions auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"

"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
Expand Down Expand Up @@ -55,7 +56,7 @@ func handleGithubCallback(w http.ResponseWriter, r *http.Request) {

var content, err = getGithubUserInfo(r.URL.Query().Get("state"), r.URL.Query().Get("code"))
if err != nil {
logic.Log("error when getting user info from github: "+err.Error(), 1)
logger.Log(1, "error when getting user info from github:", err.Error())
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
return
}
Expand All @@ -77,11 +78,11 @@ func handleGithubCallback(w http.ResponseWriter, r *http.Request) {

var jwt, jwtErr = logic.VerifyAuthRequest(authRequest)
if jwtErr != nil {
logic.Log("could not parse jwt for user "+authRequest.UserName, 1)
logger.Log(1, "could not parse jwt for user", authRequest.UserName)
return
}

logic.Log("completed github OAuth sigin in for "+content.Login, 1)
logger.Log(1, "completed github OAuth sigin in for", content.Login)
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?login="+jwt+"&user="+content.Login, http.StatusPermanentRedirect)
}

Expand Down
7 changes: 4 additions & 3 deletions auth/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"net/http"

"github.com/gravitl/netmaker/logger"
"github.com/gravitl/netmaker/logic"
"github.com/gravitl/netmaker/models"
"github.com/gravitl/netmaker/servercfg"
Expand Down Expand Up @@ -55,7 +56,7 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {

var content, err = getGoogleUserInfo(r.FormValue("state"), r.FormValue("code"))
if err != nil {
logic.Log("error when getting user info from google: "+err.Error(), 1)
logger.Log(1, "error when getting user info from google:", err.Error())
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
return
}
Expand All @@ -77,11 +78,11 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {

var jwt, jwtErr = logic.VerifyAuthRequest(authRequest)
if jwtErr != nil {
logic.Log("could not parse jwt for user "+authRequest.UserName, 1)
logger.Log(1, "could not parse jwt for user", authRequest.UserName)
return
}

logic.Log("completed google OAuth sigin in for "+content.Email, 1)
logger.Log(1, "completed google OAuth sigin in for", content.Email)
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?login="+jwt+"&user="+content.Email, http.StatusPermanentRedirect)
}

Expand Down
4 changes: 2 additions & 2 deletions compose/docker-compose.caddy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.4"
services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:v0.9.1
image: gravitl/netmaker:v0.9.2
volumes:
- /var/run/dbus/system_bus_socket:/var/run/dbus/system_bus_socket
- /run/systemd/system:/run/systemd/system
Expand Down Expand Up @@ -40,7 +40,7 @@ services:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.9.1
image: gravitl/netmaker-ui:v0.9.2
links:
- "netmaker:api"
ports:
Expand Down
4 changes: 2 additions & 2 deletions compose/docker-compose.contained.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.4"
services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:v0.9.1
image: gravitl/netmaker:v0.9.2
volumes:
- dnsconfig:/root/config/dnsconfig
- /usr/bin/wg:/usr/bin/wg
Expand Down Expand Up @@ -38,7 +38,7 @@ services:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.9.1
image: gravitl/netmaker-ui:v0.9.2
links:
- "netmaker:api"
ports:
Expand Down
4 changes: 2 additions & 2 deletions compose/docker-compose.nodns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: "3.4"
services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:v0.9.1
image: gravitl/netmaker:v0.9.2
volumes:
- /usr/bin/wg:/usr/bin/wg
- sqldata:/root/data
Expand Down Expand Up @@ -36,7 +36,7 @@ services:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.9.1
image: gravitl/netmaker-ui:v0.9.2
links:
- "netmaker:api"
ports:
Expand Down
4 changes: 2 additions & 2 deletions compose/docker-compose.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ services:
container_name: netmaker
depends_on:
- rqlite
image: gravitl/netmaker:v0.9.1
image: gravitl/netmaker:v0.9.2
volumes: # Volume mounts necessary for CLIENT_MODE to control wireguard networking on host (except dnsconfig, which is where dns config files are stored for use by CoreDNS)
- dnsconfig:/root/config/dnsconfig # Netmaker writes Corefile to this location, which gets mounted by CoreDNS for DNS configuration.
- /usr/bin/wg:/usr/bin/wg
Expand Down Expand Up @@ -41,7 +41,7 @@ services:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.9.1
image: gravitl/netmaker-ui:v0.9.2
links:
- "netmaker:api"
ports:
Expand Down
2 changes: 1 addition & 1 deletion compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ services:
container_name: netmaker-ui
depends_on:
- netmaker
image: gravitl/netmaker-ui:v0.9.1
image: gravitl/netmaker-ui:v0.9.2
links:
- "netmaker:api"
ports:
Expand Down
15 changes: 9 additions & 6 deletions controllers/authGrpc.go → controllers/auth_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"google.golang.org/grpc/status"
)

// AuthServerUnaryInterceptor - auth unary interceptor logic
func AuthServerUnaryInterceptor(ctx context.Context,
req interface{},
info *grpc.UnaryServerInfo,
Expand All @@ -38,6 +39,8 @@ func AuthServerUnaryInterceptor(ctx context.Context,

return h, err
}

// AuthServerStreamInterceptor - auth stream interceptor
func AuthServerStreamInterceptor(
srv interface{},
stream grpc.ServerStream,
Expand Down Expand Up @@ -100,7 +103,7 @@ func grpcAuthorize(ctx context.Context) error {
return nil
}

//Node authenticates using its password and retrieves a JWT for authorization.
// Login - node authenticates using its password and retrieves a JWT for authorization.
func (s *NodeServiceServer) Login(ctx context.Context, req *nodepb.Object) (*nodepb.Object, error) {

//out := new(LoginResponse)
Expand All @@ -114,15 +117,15 @@ func (s *NodeServiceServer) Login(ctx context.Context, req *nodepb.Object) (*nod
password := reqNode.Password

var result models.NodeAuth

err := errors.New("Generic server error.")
var err error
// err := errors.New("generic server error")

if macaddress == "" {
//TODO: Set Error response
err = errors.New("Missing Mac Address.")
err = errors.New("missing mac address")
return nil, err
} else if password == "" {
err = errors.New("Missing Password.")
err = errors.New("missing password")
return nil, err
} else {
//Search DB for node with Mac Address. Ignore pending nodes (they should not be able to authenticate with API until approved).
Expand Down Expand Up @@ -153,7 +156,7 @@ func (s *NodeServiceServer) Login(ctx context.Context, req *nodepb.Object) (*nod
return nil, err
}
if tokenString == "" {
err = errors.New("Something went wrong. Could not retrieve token.")
err = errors.New("something went wrong, could not retrieve token")
return nil, err
}

Expand Down
Loading

0 comments on commit a412596

Please sign in to comment.