-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,21 +20,19 @@ import ( | |
"context" | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
"net" | ||
"net/url" | ||
"strings" | ||
"sync" | ||
"time" | ||
|
||
"github.com/golang-jwt/jwt/v5" | ||
pb "github.com/jumpstarter-dev/jumpstarter-protocol/go/jumpstarter/v1" | ||
"golang.org/x/exp/slices" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/reflection" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/protobuf/types/known/durationpb" | ||
authv1 "k8s.io/api/authentication/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/labels" | ||
|
@@ -49,10 +47,6 @@ import ( | |
jumpstarterdevv1alpha1 "github.com/jumpstarter-dev/jumpstarter-controller/api/v1alpha1" | ||
) | ||
|
||
// Reference: config/default/kustomization.yaml | ||
const nameSpace = "jumpstarter-router-system" | ||
const namePrefix = "jumpstarter-router-" | ||
|
||
// ControlerService exposes a gRPC service | ||
type ControllerService struct { | ||
pb.UnimplementedControllerServiceServer | ||
|
@@ -386,60 +380,33 @@ func (s *ControllerService) Dial(ctx context.Context, req *pb.DialRequest) (*pb. | |
|
||
stream := uuid.NewUUID() | ||
|
||
audience := (&url.URL{ | ||
// TODO should we use grpc scheme? | ||
Scheme: "https", | ||
Host: routerEndpoint(), | ||
Path: fmt.Sprintf("/stream/%s", stream), | ||
}).String() | ||
|
||
// TODO: make this configurable and requestable (with limits) | ||
expsecs := int64(3600) | ||
|
||
var tokenholder corev1.ServiceAccount | ||
|
||
tokenholderName := types.NamespacedName{ | ||
Namespace: nameSpace, | ||
Name: namePrefix + "tokenholder", | ||
} | ||
|
||
if err := s.Client.Get(ctx, tokenholderName, &tokenholder); err != nil { | ||
logger.Error(err, "failed to get tokenholder service account", "name", tokenholderName) | ||
return nil, status.Errorf(codes.Internal, "failed to get tokenholder service account") | ||
} | ||
|
||
tokenRequest := authv1.TokenRequest{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Namespace: tokenholderName.Namespace, | ||
Name: tokenholderName.Name, | ||
}, | ||
Spec: authv1.TokenRequestSpec{ | ||
Audiences: []string{audience}, | ||
ExpirationSeconds: &expsecs, | ||
}, | ||
} | ||
|
||
if err := s.SubResource("token").Create(ctx, &tokenholder, &tokenRequest); err != nil { | ||
logger.Error(err, "failed to issue stream token") | ||
return nil, status.Errorf(codes.Internal, "failed to issue stream token: %s", err) | ||
} | ||
token, err := jwt.NewWithClaims(jwt.SigningMethodNone, jwt.RegisteredClaims{ | ||
Issuer: "https://jumpstarter.dev/stream", | ||
Subject: string(stream), | ||
Audience: []string{"https://jumpstarter.dev/router"}, | ||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Minute * 30)), | ||
NotBefore: jwt.NewNumericDate(time.Now()), | ||
IssuedAt: jwt.NewNumericDate(time.Now()), | ||
ID: string(uuid.NewUUID()), | ||
}).SignedString(jwt.UnsafeAllowNoneSignatureType) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
NickCao
Author
Collaborator
|
||
|
||
// TODO: find best router from list | ||
endpoint := routerEndpoint() | ||
|
||
response := &pb.ListenResponse{ | ||
RouterEndpoint: endpoint, | ||
RouterToken: tokenRequest.Status.Token, | ||
RouterToken: token, | ||
} | ||
|
||
if err := value.(listenContext).stream.Send(response); err != nil { | ||
logger.Error(err, "failed to send listen response", "response", response) | ||
return nil, err | ||
} | ||
|
||
logger.Info("Client dial assigned stream ", "client", identity.GetName(), "stream", audience) | ||
logger.Info("Client dial assigned stream ", "client", identity.GetName(), "stream", stream) | ||
return &pb.DialResponse{ | ||
RouterEndpoint: endpoint, | ||
RouterToken: tokenRequest.Status.Token, | ||
RouterToken: token, | ||
}, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
But this is not self-signed, it's un-signed