Skip to content

Commit a0b6136

Browse files
committed
Security Improvement
1 parent 0773e30 commit a0b6136

4 files changed

Lines changed: 69 additions & 96 deletions

File tree

Dockerfile-Kubernetes

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
2+
3+
RUN sed -i "s|MinProtocol = TLSv1.2|MinProtocol = TLSv1|g" /etc/ssl/openssl.cnf && \
4+
sed -i 's|CipherString = DEFAULT@SECLEVEL=2|CipherString = DEFAULT@SECLEVEL=1|g' /etc/ssl/openssl.cnf
5+
6+
RUN apt-get update && apt-get install -y --no-install-recommends curl
7+
8+
WORKDIR /app
9+
10+
COPY Gnoss.BackgroundTask.CacheRefresh/*.csproj ./
11+
12+
RUN dotnet restore
13+
14+
COPY . ./
15+
16+
RUN dotnet publish Gnoss.BackgroundTask.CacheRefresh/Gnoss.BackgroundTask.CacheRefresh.csproj -c Release -o out
17+
18+
FROM mcr.microsoft.com/dotnet/aspnet:6.0
19+
20+
RUN sed -i "s|MinProtocol = TLSv1.2|MinProtocol = TLSv1|g" /etc/ssl/openssl.cnf && \
21+
sed -i 's|CipherString = DEFAULT@SECLEVEL=2|CipherString = DEFAULT@SECLEVEL=1|g' /etc/ssl/openssl.cnf
22+
23+
RUN apt-get update && apt-get install -y --no-install-recommends curl
24+
25+
WORKDIR /app
26+
RUN useradd -r gnoss
27+
RUN chown -R gnoss:gnoss /app
28+
RUN chmod -R 777 /app
29+
USER gnoss
30+
31+
COPY --from=build-env /app/out .
32+
33+
ENTRYPOINT ["dotnet", "Gnoss.BackgroundTask.CacheRefresh.dll"]

Gnoss.BackgroundTask.CacheRefresh/ControladorRefrescoCache.cs

Lines changed: 8 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ internal class ControladorRefrescoCache : ControladorServicioGnoss
5656

5757
#region Miembros
5858

59-
//private Dictionary<Guid, DateTime> ListaFechasCaducidadComponentes = new Dictionary<Guid, DateTime>();
60-
61-
//private Dictionary<Guid, CMSDS.CMSComponenteRow> ListaComponentes = new Dictionary<Guid, CMSDS.CMSComponenteRow>();
62-
63-
//private Dictionary<Guid, List<CMSDS.CMSComponenteRow>> ListaComponentesCaducidadRecursoPorProyecto = new Dictionary<Guid, List<CMSDS.CMSComponenteRow>>();
64-
65-
//private CMSDS mCmsDS = null;
6659
/// <summary>
6760
/// Almacena la lista de peticiones web actuales por dominio
6861
/// </summary>
@@ -161,7 +154,7 @@ private bool ProcesarItem(string pFila)
161154
filaCola = null;
162155

163156
ControladorConexiones.CerrarConexiones(false);
164-
UtilPeticion.EliminarObjetosDeHilo(Thread.CurrentThread.ManagedThreadId);
157+
//UtilPeticion.EliminarObjetosDeHilo(Thread.CurrentThread.ManagedThreadId);
165158
}
166159
return true;
167160
}
@@ -241,12 +234,12 @@ protected void RealizarMantenimientoRabbitMQ(LoggingService loggingService, bool
241234
mReiniciarLecturaRabbit = true;
242235
loggingService.GuardarLogError(ex);
243236
}
244-
245237
}
246238
}
247239

248240
protected void RealizarMantenimientoBaseDatosColas()
249241
{
242+
250243
while (true)
251244
{
252245
using (var scope = ScopedFactory.CreateScope())
@@ -264,63 +257,6 @@ protected void RealizarMantenimientoBaseDatosColas()
264257
{
265258
ComprobarCancelacionHilo();
266259

267-
if (mReiniciarLecturaRabbit)
268-
{
269-
RealizarMantenimientoRabbitMQ(loggingService);
270-
}
271-
272-
BaseComunidadCN baseComunidadCN = new BaseComunidadCN(entityContext, loggingService, entityContextBASE, mConfigService, servicesUtilVirtuosoAndReplication);
273-
baseComunidadCN.EliminarColaRefrescoCachePendientesRepetidas();
274-
BaseComunidadDS baseComunidadDS = baseComunidadCN.ObtenerColaRefrescoCachePendientes();
275-
276-
Dictionary<Guid, List<short>> listaBusquedasRefresco = new Dictionary<Guid, List<short>>();
277-
foreach (BaseComunidadDS.ColaRefrescoCacheRow filaCola in baseComunidadDS.ColaRefrescoCache.Rows)
278-
{
279-
EstaHiloActivo = true;
280-
filaCola.Estado = 0;
281-
282-
if (filaCola.TipoEvento == (short)TiposEventosRefrescoCache.ModificarCaducidadCache)
283-
{
284-
try
285-
{
286-
ProcesarFilaModificarCaducidadCache(filaCola, entityContext, loggingService, redisCacheWrapper, servicesUtilVirtuosoAndReplication);
287-
}
288-
catch (ThreadAbortException) { }
289-
catch (Exception ex)
290-
{
291-
filaCola.Estado = 1;
292-
EnviarCorreoErrorYGuardarLog(ex, "Error Refresco caché (ProcesarFilaModificarCaducidadCache)", entityContext, loggingService);
293-
}
294-
}
295-
else
296-
{
297-
if (!listaBusquedasRefresco.ContainsKey(filaCola.ProyectoID))
298-
{
299-
listaBusquedasRefresco.Add(filaCola.ProyectoID, new List<short>());
300-
}
301-
if (listaBusquedasRefresco[filaCola.ProyectoID].Contains(filaCola.TipoBusqueda))
302-
{
303-
baseComunidadCN.EliminarFilaColaRefrescoCache(filaCola.ColaID);
304-
continue;
305-
}
306-
else
307-
{
308-
listaBusquedasRefresco[filaCola.ProyectoID].Add(filaCola.TipoBusqueda);
309-
}
310-
311-
ComprobarCancelacionHilo();
312-
313-
ProcesarFila(filaCola, entityContext, loggingService, redisCacheWrapper, virtuosoAD, servicesUtilVirtuosoAndReplication);
314-
}
315-
if (filaCola.Estado == 0)
316-
{
317-
baseComunidadCN.EliminarFilaColaRefrescoCache(filaCola.ColaID);
318-
}
319-
else
320-
{
321-
baseComunidadCN.AcutalizarEstadoColaRefrescoCache(filaCola.ColaID, filaCola.Estado);
322-
}
323-
}
324260

325261
List<CMSComponente> listaComponentesRefresco = CargarComponentesCaducados(entityContext, loggingService, servicesUtilVirtuosoAndReplication);
326262
//Esto lo tengo que hacer en un foreach aparte porque si no salta la excepción de Colleción modificada
@@ -330,8 +266,6 @@ protected void RealizarMantenimientoBaseDatosColas()
330266
}
331267

332268
ComprobarCancelacionHilo();
333-
334-
//ControladorConexiones.CerrarConexiones(false);
335269
}
336270
catch (ThreadAbortException) { }
337271
catch (OperationCanceledException)
@@ -368,27 +302,9 @@ public override void RealizarMantenimiento(EntityContext entityContext, EntityCo
368302
{
369303
mDominio = mDominio.Substring(0, mDominio.Length - 1);
370304
}
371-
if (mConfigService.UsarCacheRefreshActiva())
372-
{
373-
while (true)
374-
{
375-
Task tarea = Task.Factory.StartNew(() => RealizarMantenimientoRabbitMQ(loggingService));
376-
377-
Thread.Sleep(60000); // 1 minuto
378305

379-
if (mRabbitMQClient != null)
380-
{
381-
mRabbitMQClient.CerrarConexionLectura();
382-
mRabbitMQClient.Dispose();
383-
}
384-
385-
Thread.Sleep(300000);// 5 minutos
386-
}
387-
}
388-
else
389-
{
390-
RealizarMantenimientoRabbitMQ(loggingService);
391-
}
306+
Task tarea = Task.Factory.StartNew(() => RealizarMantenimientoRabbitMQ(loggingService));
307+
Task tarea2 = Task.Factory.StartNew(() => RealizarMantenimientoBaseDatosColas());
392308
}
393309

394310
private void ProcesarFila(BaseComunidadDS.ColaRefrescoCacheRow pFilaCola, EntityContext entityContext, LoggingService loggingService, RedisCacheWrapper redisCacheWrapper, VirtuosoAD virtuosoAD, IServicesUtilVirtuosoAndReplication servicesUtilVirtuosoAndReplication)
@@ -894,10 +810,10 @@ private void RefrescarCacheComponente(Guid pComponenteID, Guid pProyectoID, Enti
894810

895811
CMSComponente filaComponente = null;
896812
CMSCN cmsCN = new CMSCN(entityContext, loggingService, mConfigService, servicesUtilVirtuosoAndReplication);
897-
DataWrapperCMS cmsDW = cmsCN.ObtenerComponentePorID(pComponenteID, pProyectoID);
813+
DataWrapperCMS cmsDW = cmsCN.ObtenerComponentePorID(pComponenteID, pProyectoID, false);
898814
if (cmsDW.ListaCMSComponente.Count > 0)
899815
{
900-
filaComponente = cmsCN.ObtenerComponentePorID(pComponenteID, pProyectoID).ListaCMSComponente.FirstOrDefault();
816+
filaComponente = cmsCN.ObtenerComponentePorID(pComponenteID, pProyectoID, false).ListaCMSComponente.FirstOrDefault();
901817
}
902818
cmsCN.Dispose();
903819

@@ -937,7 +853,7 @@ private string ObtenerDominioComunidad(Guid pOrganizacionID, Guid pProyectoID, E
937853

938854
private string ObtenerURLRefrescoComponente(CMSComponente pFilaComponente, EntityContext entityContext, LoggingService loggingService, IServicesUtilVirtuosoAndReplication servicesUtilVirtuosoAndReplication)
939855
{
940-
return ObtenerDominioComunidad(pFilaComponente.OrganizacionID, pFilaComponente.ProyectoID, entityContext, loggingService, servicesUtilVirtuosoAndReplication).TrimEnd('/') + "/cmspagina?proyectoid=" + pFilaComponente.ProyectoID + "&componenteid=" + pFilaComponente.ComponenteID;
856+
return $"{ObtenerDominioComunidad(pFilaComponente.OrganizacionID, pFilaComponente.ProyectoID, entityContext, loggingService, servicesUtilVirtuosoAndReplication).TrimEnd('/')}/cmspagina?proyectoid={pFilaComponente.ProyectoID}&componenteid={pFilaComponente.ComponenteID}&refrescar=true";
941857
}
942858

943859
private void RealizarPeticionWebRefrescoCache(CMSComponente pFilaComponente, EntityContext entityContext, LoggingService loggingService, RedisCacheWrapper redisCacheWrapper, IServicesUtilVirtuosoAndReplication servicesUtilVirtuosoAndReplication)
@@ -985,6 +901,7 @@ private void RealizarPeticionWebRefrescoCache(CMSComponente pFilaComponente, Ent
985901
realizarPeticion.PeticionesWebActuales = mPeticionesWebActuales;
986902

987903
Task.Factory.StartNew(realizarPeticion.EmpezarMantenimiento);
904+
//Task.Factory.StartNew(realizarPeticion.RealizarMantenimiento(entityContext, null, null, loggingService, redisCacheWrapper, null, null, servicesUtilVirtuosoAndReplication));
988905

989906
Thread.Sleep(1000);
990907
}

Gnoss.BackgroundTask.CacheRefresh/Gnoss.BackgroundTask.CacheRefresh.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
1010
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="5.0.1" />
1111
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="5.0.1" />
12-
<PackageReference Include="Npgsql" Version="6.0.9" />
12+
<PackageReference Include="Npgsql" Version="6.0.11" />
1313
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.8" />
1414
<PackageReference Include="Oracle.EntityFrameworkCore" Version="6.21.90" />
1515
</ItemGroup>

Gnoss.BackgroundTask.CacheRefresh/Program.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,21 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
3838
.ConfigureServices((hostContext, services) =>
3939
{
4040
IConfiguration configuration = hostContext.Configuration;
41-
services.AddScoped(typeof(UtilTelemetry));
41+
ILoggerFactory loggerFactory =
42+
LoggerFactory.Create(builder =>
43+
{
44+
builder.AddConfiguration(configuration.GetSection("Logging"));
45+
builder.AddSimpleConsole(options =>
46+
{
47+
options.IncludeScopes = true;
48+
options.SingleLine = true;
49+
options.TimestampFormat = "yyyy-MM-dd HH:mm:ss ";
50+
options.UseUtcTimestamp = true;
51+
});
52+
});
53+
services.AddSingleton(loggerFactory);
54+
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
55+
services.AddScoped(typeof(UtilTelemetry));
4256
services.AddScoped(typeof(Usuario));
4357
services.AddScoped(typeof(UtilPeticion));
4458

@@ -59,13 +73,12 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
5973
{
6074
bdType = configuration.GetConnectionString("connectionType");
6175
}
62-
if (bdType.Equals("2"))
76+
if (bdType.Equals("2") || bdType.Equals("1"))
6377
{
6478
services.AddScoped(typeof(DbContextOptions<EntityContext>));
6579
services.AddScoped(typeof(DbContextOptions<EntityContextBASE>));
6680
}
6781
services.AddSingleton<ConfigService>();
68-
services.AddSingleton<ILoggerFactory, LoggerFactory>();
6982

7083
string acid = "";
7184
if (environmentVariables.Contains("acid"))
@@ -95,7 +108,17 @@ public static IHostBuilder CreateHostBuilder(string[] args) =>
95108

96109
);
97110
}
98-
else if (bdType.Equals("2"))
111+
else if (bdType.Equals("1"))
112+
{
113+
services.AddDbContext<EntityContext, EntityContextOracle>(options =>
114+
options.UseOracle(acid)
115+
);
116+
services.AddDbContext<EntityContextBASE, EntityContextBASEOracle>(options =>
117+
options.UseOracle(baseConnection)
118+
119+
);
120+
}
121+
else if (bdType.Equals("2"))
99122
{
100123
services.AddDbContext<EntityContext, EntityContextPostgres>(opt =>
101124
{

0 commit comments

Comments
 (0)