-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Host and port binding environment variables for pk agent start
#286
Comments
Due to refactoring the CLI in https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213#note_721718865 I'm seeing the usecase of defining options in Right now I'm creating: function parseNumber(v: string): number {
const num = parseInt(v);
if (isNaN(num)) {
throw new commander.InvalidOptionArgumentError(`${v} is not a number`);
}
return num;
}
const clientHost = new commander.Option(
'-ch, --client-host <address>',
'Client Host Address'
).env('PK_CLIENT_HOST').default('127.0.0.1');
const clientPort = new commander.Option(
'-cp, --client-port <port>',
'Client Port'
).argParser(parseNumber).env('PK_CLIENT_PORT').default(0); Note that I upgraded to commander 8.3.0. See the MR for details. |
Having a look at the await this.agentGrpcServer.start({
services: [[AgentService, this.agentService]],
host: this.agentGrpcHost as Host,
port: this.agentGrpcPort as Port,
});
// ...
await this.revProxy.start({
serverHost: this.agentGrpcHost as Host,
serverPort: this.agentGrpcServer.getPort() as Port,
tlsConfig: {
keyPrivatePem: keyPrivatePem,
certChainPem: certChainPem,
},
}); I think how i had the host and port set here is wrong. we don't care what the agent server's host and port are so long as we pass it to the revProxy, However we want to set the ingress host and port for the revProxy here right? I will need to update this. |
Ok, fixed that part. |
I made |
Unless I'm missing anything this should be done pending the merge of #283 |
This is done, but requires further testing under |
Testing has been done with specified network configuration. |
Block 2 from #194 (comment)
Specification
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: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 start
flagsrc/config.ts
)ReverseProxy
ingress host--ingress-host
PK_INGRESS_HOST
0.0.0.0
ReverseProxy
ingress port--ingress-port
PK_INGRESS_PORT
GRPCServer
public-facing host--client-host
PK_CLIENT_HOST
127.0.0.1
)GRPCServer
public-facing port--client-port
PK_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
::1
though.)Also note that defaulting the ports to 0 eventually randomises the port allocation in the
GRPCServer
andReverseProxy
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:
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.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 theStartStop
decoratorTasks
pk agent start
flags for all hosts and ports--ingress-host
CLI parameters being providedparseHost
parsePort
pk agent start
flag > environment variable > default value
.env.example
src/bin/options.ts
pk agent start
--ingress-host
The text was updated successfully, but these errors were encountered: