You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pk agent start will be used inside a docker container as the initial command. This means it has to bind to the container host and relevant ports:
the PK agent runs with ingressHost and ingressPort used by reverse proxy, this must specified ahead of time in the TD
the PK agent also requires a specification for the GRPCServer host and port, as this is used directly by the CLI that doesn't go through the reverse proxy
Therefore, we need environment variables for:
PK_INGRESS_HOST + PK_INGRESS_PORT: the public-facing host and port of the ReverseProxy
PK_CLIENT_HOST + PK_CLIENT_PORT: the public-facing host and port of the GRPC server (to remotely interact with the client service on the AWS instance of Polykey from our own devices)
Variable specification
We expect the variables to have the following properties:
Variable
pk agent start flag
.env variable
Default value (src/config.ts)
ReverseProxy ingress host
--ingress-host
PK_INGRESS_HOST
0.0.0.0
ReverseProxy ingress port
--ingress-port
PK_INGRESS_PORT
0
GRPCServer public-facing host
--client-host
PK_CLIENT_HOST
localhost (127.0.0.1)
GRPCServer public-facing port
--client-port
PK_CLIENT_PORT
0
(Note that the default host values are only with reference to IPv4 addresses - we don't currently support IPv6. The default IPv6 host would be expected to be ::1 though.)
Also note that defaulting the ports to 0 eventually randomises the port allocation in the GRPCServer and ReverseProxy when the port is bound to the GRPC server and UTP socket respectively.
To future-proof for supporting IPv6, we should also support being able to specify --ingress-host multiple times. This would be used such that we can bind to both an IPv4 and IPv6 host at the same time.
Similarly to the password and recovery code, the precedence for these variables would be: flag > environment variable > default value.
Parsing utility functions
We'll also require some parsing utility functions for these hosts and ports. For example, for a port:
functionparsePort(value: string|undefined): number{letport=parseInt(value??'0');if(isNaN(port)){// port = 0;// perhaps instead throw an exception here? See belowthrownewclientErrors.ErrorMalformedPort();}returnport;}
I'm suggesting that with these parsing functions, instead of returning some default value though (e.g. with parsePort here, we return 0), we'd want to instead throw an exception. The idea with that is, if the passed host/port is wrong (from the parameters, environment variable, wherever), we open the PK agent up to performing unexpected behaviour.
For example, if we had a malformed port in our environment variable, no exception would be thrown, and it would be defaulted to 0. Ideally, we should instead inform the user that the host/port is malformed, and it should be fixed. However, if the host/port is simply missing, then we can use the default value.
These can be integrated with the getFrom...() functions that will be created in #202. For example:
try{ingressPort=parsePort(getFromParams()??getFromEnv('PK_INGRESS_PORT')??getFromConfig());catch(e){if(einstanceofclientErrors.ErrorMalformedPort){// retry? Ask from STDIN? Handle in some way. // Perhaps just let it bubble up to the CLI display without handling}throwe;}
Testnet Node Deployment (testnet.polykey.io) #194 (comment) - comment regarding the propagation of the start() method parameters to the async creation, this is required since the networking domain objects are likely to be using the StartStop decorator
Block 2 from #194 (comment)
Specification
The
pk agent startwill be used inside a docker container as the initial command. This means it has to bind to the container host and relevant ports:Therefore, we need environment variables for:
PK_INGRESS_HOST+PK_INGRESS_PORT: the public-facing host and port of the ReverseProxyPK_CLIENT_HOST+PK_CLIENT_PORT: the public-facing host and port of the GRPC server (to remotely interact with the client service on the AWS instance of Polykey from our own devices)Variable specification
We expect the variables to have the following properties:
pk agent startflagsrc/config.ts)ReverseProxyingress host--ingress-hostPK_INGRESS_HOST0.0.0.0ReverseProxyingress port--ingress-portPK_INGRESS_PORTGRPCServerpublic-facing host--client-hostPK_CLIENT_HOST127.0.0.1)GRPCServerpublic-facing port--client-portPK_CLIENT_PORT(Note that the default host values are only with reference to IPv4 addresses - we don't currently support IPv6. The default IPv6 host would be expected to be
::1though.)Also note that defaulting the ports to 0 eventually randomises the port allocation in the
GRPCServerandReverseProxywhen the port is bound to the GRPC server and UTP socket respectively.To future-proof for supporting IPv6, we should also support being able to specify
--ingress-hostmultiple times. This would be used such that we can bind to both an IPv4 and IPv6 host at the same time.Similarly to the password and recovery code, the precedence for these variables would be:
flag > environment variable > default value.Parsing utility functions
We'll also require some parsing utility functions for these hosts and ports. For example, for a port:
parsePorthere, we return 0), we'd want to instead throw an exception. The idea with that is, if the passed host/port is wrong (from the parameters, environment variable, wherever), we open the PK agent up to performing unexpected behaviour.These can be integrated with the
getFrom...()functions that will be created in #202. For example:Additional context
start()method parameters to the async creation, this is required since the networking domain objects are likely to be using theStartStopdecoratorTasks
pk agent startflags for all hosts and ports--ingress-hostCLI parameters being providedparseHostparsePortpk agent startflag > environment variable > default value.env.examplesrc/bin/options.tspk agent start--ingress-host