@@ -203,6 +203,28 @@ func server() *cobra.Command {
203
203
_ ,_ = fmt .Fprintln (cmd .ErrOrStderr ())
204
204
}
205
205
206
+ // Warn the user if the access URL appears to be a loopback address.
207
+ isLocal ,err := isLocalURL (cmd .Context (),accessURL )
208
+ if isLocal || err != nil {
209
+ var reason string
210
+ if isLocal {
211
+ reason = "appears to be a loopback address"
212
+ }else {
213
+ reason = "could not be resolved"
214
+ }
215
+ _ ,_ = fmt .Fprintf (cmd .ErrOrStderr (),cliui .Styles .Wrap .Render (
216
+ cliui .Styles .Warn .Render ("Warning:" )+ " The current access URL:" )+ "\n \n " )
217
+ _ ,_ = fmt .Fprintf (cmd .ErrOrStderr ()," " + cliui .Styles .Field .Render (accessURL )+ "\n \n " )
218
+ _ ,_ = fmt .Fprintf (cmd .ErrOrStderr (),cliui .Styles .Wrap .Render (
219
+ reason + ". Provisioned workspaces are unlikely to be able to " +
220
+ "connect to Coder. Please consider changing your " +
221
+ "access URL using the --access-url option, or directly " +
222
+ "specifying access URLs on templates." ,
223
+ )+ "\n \n " )
224
+ _ ,_ = fmt .Fprintf (cmd .ErrOrStderr (),"For more information, see " +
225
+ "https://github.com/coder/coder/issues/1528\n \n " )
226
+ }
227
+
206
228
validator ,err := idtoken .NewValidator (cmd .Context (),option .WithoutAuthentication ())
207
229
if err != nil {
208
230
return err
@@ -803,3 +825,24 @@ func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler,
803
825
804
826
return func () {_ = srv .Close () }
805
827
}
828
+
829
+ // isLocalURL returns true if the hostname of the provided URL appears to
830
+ // resolve to a loopback address.
831
+ func isLocalURL (ctx context.Context ,urlString string ) (bool ,error ) {
832
+ parsedURL ,err := url .Parse (urlString )
833
+ if err != nil {
834
+ return false ,err
835
+ }
836
+ resolver := & net.Resolver {}
837
+ ips ,err := resolver .LookupIPAddr (ctx ,parsedURL .Hostname ())
838
+ if err != nil {
839
+ return false ,err
840
+ }
841
+
842
+ for _ ,ip := range ips {
843
+ if ip .IP .IsLoopback () {
844
+ return true ,nil
845
+ }
846
+ }
847
+ return false ,nil
848
+ }