[release] v0.10.0-unstable13

This commit is contained in:
Yann Stepienik 2023-09-05 20:06:20 +01:00
parent 07e7f634b7
commit a57dbc806b
8 changed files with 1670 additions and 1270 deletions

File diff suppressed because it is too large Load diff

View file

@ -72,7 +72,7 @@ const AddDeviceModal = ({ users, config, isAdmin, refreshConfig, devices }) => {
return API.constellation.addDevice(values).then(({data}) => {
setIsDone(data);
refreshConfig();
renderCanvas(data);
renderCanvas(data.Config);
}).catch((err) => {
setErrors(err.response.data);
});
@ -92,24 +92,24 @@ const AddDeviceModal = ({ users, config, isAdmin, refreshConfig, devices }) => {
</p>
<Stack spacing={2} direction={"column"}>
<CosmosFormDivider title={"Cosmos Client (QR Code)"} />
<CosmosFormDivider title={"QR Code"} />
<div style={{textAlign: 'center'}}>
<canvas style={{borderRadius: '15px'}} ref={canvasRef} />
</div>
<CosmosFormDivider title={"Cosmos Client (File)"} />
{/* <CosmosFormDivider title={"Cosmos Client (File)"} />
<DownloadFile
filename={isDone.DeviceName + `.constellation`}
content={JSON.stringify(isDone, null, 2)}
label={"Download " + isDone.DeviceName + `.constellation`}
/>
<CosmosFormDivider title={"Nebula Client"} />
/> */}
<CosmosFormDivider title={"File"} />
<DownloadFile
filename={`config.yml`}
filename={`constellation.yml`}
content={isDone.Config}
label={"Download config.yml"}
label={"Download constellation.yml"}
/>
<DownloadFile
{/* <DownloadFile
filename={isDone.DeviceName + `.key`}
content={isDone.PublicKey}
label={"Download " + isDone.DeviceName + `.key`}
@ -123,7 +123,7 @@ const AddDeviceModal = ({ users, config, isAdmin, refreshConfig, devices }) => {
filename={`ca.crt`}
content={isDone.CA}
label={"Download ca.crt"}
/>
/> */}
</Stack>
</DialogContentText>
</DialogContent> : <DialogContent>

View file

@ -1,6 +1,6 @@
{
"name": "cosmos-server",
"version": "0.10.0-unstable12",
"version": "0.10.0-unstable13",
"description": "",
"main": "test-server.js",
"bugs": {

View file

@ -7,7 +7,7 @@
<p align="center"><a href="https://github.com/DrMxrcy"><img src="https://avatars.githubusercontent.com/DrMxrcy" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/soldier1"><img src="https://avatars.githubusercontent.com/soldier1" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
<a href="https://github.com/devcircus"><img src="https://avatars.githubusercontent.com/devcircus" style="border-radius:48px" width="48" height="48" alt="Clayton Stone" title="Clayton Stone" /></a>
<a href="https://github.com/Serph91P"><img src="https://avatars.githubusercontent.com/Serph91P" style="border-radius:48px" width="48" height="48" alt="Seraph91P" title="Seraph91P" /></a>
<a href="https://github.com/BlackrazorNZ"><img src="https://avatars.githubusercontent.com/BlackrazorNZ" style="border-radius:48px" width="48" height="48" alt="null" title="null" /></a>
</p><!-- /sponsors -->
---

View file

@ -5,7 +5,6 @@ import (
"strconv"
"strings"
"io/ioutil"
"fmt"
"github.com/miekg/dns"
"github.com/azukaar/cosmos-server/src/utils"
@ -41,52 +40,6 @@ func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
// []string hostnames
hostnames := utils.GetAllHostnames(false, true)
originalHostname := hostnames[0]
specialQuery := false
// if lighthouse-cosmos.constellation is the query, return originalHostname's external lookup
for i, q := range r.Question {
if strings.HasSuffix(q.Name, "lighthouse-cosmos.constellation.") {
utils.Debug("DNS Overwrite lighthouse-cosmos.constellation with " + originalHostname)
// Create a deep copy of the original request.
modifiedRequest := r.Copy()
client := new(dns.Client)
// Modify only the copied request.
modifiedRequest.Question[i].Name = originalHostname + "."
externalResponse, time, err := externalLookup(client, modifiedRequest, DNSFallback)
if err != nil {
utils.Error("Failed to forward query:", err)
return
}
utils.Debug("DNS Forwarded DNS query to "+DNSFallback+" in " + time.String())
for _, rr := range externalResponse.Answer {
if aRecord, ok := rr.(*dns.A); ok {
// 2. Replace the hostname with "lighthouse-cosmos.constellation".
modifiedString := fmt.Sprintf("lighthouse-cosmos.constellation. A %s", aRecord.A.String())
// 3. Convert the string back into a dns.RR.
newRR, err := dns.NewRR(modifiedString)
if err != nil {
utils.Error("Failed to convert string into dns.RR:", err)
return
}
// Replace the response RR with the new RR.
r.Answer = append(r.Answer, newRR)
}
}
m = r
specialQuery = true
}
}
if !customHandled {
customDNSEntries := config.ConstellationConfig.CustomDNSEntries
@ -104,7 +57,7 @@ func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
}
}
if !specialQuery {
if !customHandled {
// Overwrite local hostnames with Constellation IP
for _, q := range r.Question {
utils.Debug("DNS Question " + q.Name)
@ -117,37 +70,37 @@ func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
}
}
}
}
if !customHandled {
// Block blacklisted domains
for _, q := range r.Question {
noDot := strings.TrimSuffix(q.Name, ".")
if DNSBlacklist[noDot] {
if q.Qtype == dns.TypeA {
utils.Debug("DNS Block " + noDot)
rr, _ := dns.NewRR(q.Name + " A 0.0.0.0")
m.Answer = append(m.Answer, rr)
}
customHandled = true
if !customHandled {
// Block blacklisted domains
for _, q := range r.Question {
noDot := strings.TrimSuffix(q.Name, ".")
if DNSBlacklist[noDot] {
if q.Qtype == dns.TypeA {
utils.Debug("DNS Block " + noDot)
rr, _ := dns.NewRR(q.Name + " A 0.0.0.0")
m.Answer = append(m.Answer, rr)
}
customHandled = true
}
}
}
// If not custom handled, use external DNS
if !customHandled {
client := new(dns.Client)
externalResponse, time, err := externalLookup(client, r, DNSFallback)
if err != nil {
utils.Error("Failed to forward query:", err)
return
}
utils.Debug("DNS Forwarded DNS query to "+DNSFallback+" in " + time.String())
externalResponse.Id = r.Id
m = externalResponse
// If not custom handled, use external DNS
if !customHandled {
client := new(dns.Client)
externalResponse, time, err := externalLookup(client, r, DNSFallback)
if err != nil {
utils.Error("Failed to forward query:", err)
return
}
utils.Debug("DNS Forwarded DNS query to "+DNSFallback+" in " + time.String())
externalResponse.Id = r.Id
m = externalResponse
}
w.WriteMsg(m)

View file

@ -81,15 +81,6 @@ func DeviceCreate(w http.ResponseWriter, req *http.Request) {
return
}
// read configYml from config/nebula.yml
configYml, err := getYAMLClientConfig(deviceName, utils.CONFIGFOLDER + "nebula.yml")
if err != nil {
utils.Error("DeviceCreation: Error while reading config", err)
utils.HTTPError(w, "Device Creation Error: " + err.Error(),
http.StatusInternalServerError, "DC005")
return
}
capki, err := getCApki()
if err != nil {
utils.Error("DeviceCreation: Error while reading ca.crt", err)
@ -98,6 +89,15 @@ func DeviceCreate(w http.ResponseWriter, req *http.Request) {
return
}
// read configYml from config/nebula.yml
configYml, err := getYAMLClientConfig(deviceName, utils.CONFIGFOLDER + "nebula.yml", capki, cert, key)
if err != nil {
utils.Error("DeviceCreation: Error while reading config", err)
utils.HTTPError(w, "Device Creation Error: " + err.Error(),
http.StatusInternalServerError, "DC005")
return
}
json.NewEncoder(w).Encode(map[string]interface{}{
"status": "OK",
"data": map[string]interface{}{

View file

@ -86,7 +86,6 @@ func ExportConfigToYAML(overwriteConfig utils.ConstellationConfig, outputPath st
finalConfig.StaticHostMap = map[string][]string{
"192.168.201.1": []string{
"lighthouse-cosmos.constellation:4242",
utils.GetMainConfig().HTTPConfig.Hostname + ":4242",
},
}
@ -119,7 +118,7 @@ func ExportConfigToYAML(overwriteConfig utils.ConstellationConfig, outputPath st
return nil
}
func getYAMLClientConfig(name, configPath string) (string, error) {
func getYAMLClientConfig(name, configPath, capki, cert, key string) (string, error) {
utils.Log("Exporting YAML config for " + name + " with file " + configPath)
// Read the YAML config file
@ -137,7 +136,6 @@ func getYAMLClientConfig(name, configPath string) (string, error) {
if staticHostMap, ok := configMap["static_host_map"].(map[interface{}]interface{}); ok {
staticHostMap["192.168.201.1"] = []string{
"lighthouse-cosmos.constellation:4242",
utils.GetMainConfig().HTTPConfig.Hostname + ":4242",
}
} else {
@ -156,9 +154,9 @@ func getYAMLClientConfig(name, configPath string) (string, error) {
}
if pkiMap, ok := configMap["pki"].(map[interface{}]interface{}); ok {
pkiMap["ca"] = "ca.crt"
pkiMap["cert"] = name + ".crt"
pkiMap["key"] = name + ".key"
pkiMap["ca"] = capki
pkiMap["cert"] = cert
pkiMap["key"] = key
} else {
return "", errors.New("pki not found in nebula.yml")
}
@ -170,6 +168,8 @@ func getYAMLClientConfig(name, configPath string) (string, error) {
return "", errors.New("relay not found in nebula.yml")
}
configMap["deviceName"] = name
// export configMap as YML
yamlData, err = yaml.Marshal(configMap)
if err != nil {

View file

@ -85,6 +85,8 @@ func RouterGen(route utils.ProxyRouteConfig, router *mux.Router, destination htt
}
}
destination = utils.Restrictions(route.RestrictToConstellation)(destination)
destination = SmartShieldMiddleware(route.Name, route.SmartShield)(destination)
originCORS := route.CORSOrigin
@ -143,8 +145,6 @@ func RouterGen(route utils.ProxyRouteConfig, router *mux.Router, destination htt
destination = utils.SetSecurityHeaders(destination)
}
destination = utils.Restrictions(route.RestrictToConstellation)(destination)
destination = tokenMiddleware(route.AuthEnabled, route.AdminOnly)(utils.CORSHeader(originCORS)((destination)))
origin.Handler(destination)